Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include filename expansion in terminal_basics.txt #33

Open
marcedelmann opened this issue Apr 19, 2022 · 1 comment
Open

Include filename expansion in terminal_basics.txt #33

marcedelmann opened this issue Apr 19, 2022 · 1 comment

Comments

@marcedelmann
Copy link

Shell Globbing

After the inclusion of tab completion in #30 the expansion of filenames by the shell using the asterisk * wild card may additionally included.

The asterisk * matches everything in the current directory (excluding ./, ../, and any filename starting with a period, e.g. .bashrc) or the greatest possible match with the pattern given before or after it. This way, may similar files can be acted upon using only one command.

Example

Suppose there are several files in the current directory. Some are Python scripts ending in .py, some are folders (indicated below with a trailing forward slash /) starting with 001- in their filename, and others match neither of these two requirements. A file listing may show:

001-1/  001-4/  001-7/  001-do_not_delete.txt  results/
001-2/  001-5/  001-8/  export-results.py      run-calculations.py
001-3/  001-6/  001-9/  heisenberg.jpeg        terminal_basics.txt

Suppose all folders starting with 001- are to be deleted retainig the results folder, all Python scripts copied one folder up, and all other files left untouched.

This can be acieved with two commands:

rm -r 001-*/
cp *.py ../

In the first line any file with a filename starting with 001- and also ending with a / (identifying it as directory) is deleted.
The second line matches any file with a filename ending in .py.

The example listing after execution of the two commands is

001-do_not_delete.txt  heisenberg.jpeg  run-calculations.py
export-results.py      results/         terminal_basics.txt

with only the undesired folders removed and the Python scripts also available in the folder above the current one.

@ElkeF
Copy link
Owner

ElkeF commented Apr 19, 2022

This sounds like a good idea. Where would you put it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants