Using the shell features as discussed in MOVING FILES, we had looked at using the shell feature to manipulate multiple files in one instance. In the example, the shell automatically found out what the user meant by the requirements between the square braces “[” “]”. Coincidentally, the shell can substitute a range of numbers, lower and upper case characters, and as many characters as you want with an asterisk. You can use many substitutions simultaneously because the shell handles these substitutions very logically. For instance, the bash shell finds no problems with expressions such as the ls dirname/*/*/*[2-3]. However, in other shells, we use the asterisk to minimize the efforts of typing. For instance, instead of entering cd directory, you enter cd dir*. In the Bash GNU, this is not necessary because the shell has a feature called file name completion which makes it possible to type the first few characters of a command and the shell finds what you are looking for. For instance, in a directory full of files, you can search for files beginning with the letter A by typing Is A and double pressing the tab key rather than the enter key. Let us have a look at some of the LINUX ADVANCED AND FUNCTIONS AND COMMANDS.
The simplest way to search for files is by the help of which command to search for directories indexed in the user search path. The path only contains files or directories containing executable files or programs, which makes the “which” command redundant. The “which” command is especially convenient when diagnosing “command not found”. Let us look at an example where our user “john” cannot use the acroread program, while a colleague of his has no problems with the program on the same system. The colleague tells John that he can see the program in /opt/acroread/bin but the directory is not in the path:
We can solve this problem by commanding the full path to run. Alternatively, we can re-export the content of the variable path:
The command (the which command) also checks whether the command is an alias for another command:
gerrit:~> which -a ls ls is aliased to `ls -F --color=auto' ls is /bin/ls
If the above command does not work, you can use the alias command
tille@www:~/mail$ alias ls alias ls='ls --color'
The find tool is the real tool to use when searching for directories that are not in the path. It is a very powerful tool, but most users consider it a somewhat difficult syntax. The GNU find on the other hand handles syntax problems. The command allows you to search file names and access file sizes, dates of change and almost all the other file property changes.
This means look in all subdirectories and files in the specified path and print a list of all the files with a name of the search criteria (string name and not the content), you can use the search command to search for files of a certain size. For example, let us assume our user john wants to find files larger than 5mb:
john:~> find . -size +5000k psychotic_chaos.mp3
Get Updates on Tech posts, Interview & Certification questions and training schedules