bash3 - Grinshpon/Shell-and-Git GitHub Wiki

Commands and Permissions

Looking at the ls command, we can provide an argument to it in the form of the directory that we want it to look at.

$ ls Documents
$ ls /

It's capable of doing more than just listing the contents of a directory. But to tap into its potential, we should look at one other command, man. The man command will take an argument in the form of another command, and provide a manual for that command.

$ man ls

Many other commands take arguments and options as well. Options are arguments preceded by a slash or double slash, and most commands will take a --help option and provide a quick reference as to what you can do.

$ ls --help

From here we can see that ls -a, we can see any hidden files (hidden files start with a period, such as .bashrc). The -R option will show all subdirectories recursively, and the -F option will append an indicator as to what kind of file it is.

$ ls -a
$ ls -R
$ ls -F

Now onto other commands. cd was explained earlier, and touch was used to create an empty file, but to create an empty directory, there is the mkdir command

$ mkdir NewDir
$ ls

To remove files and directories we have rm and rmdir respectively

$ rm example.txt
$ rmdir NewDir

Although, rm has an option -r to remove directories by recursively removing all their contents. You must be careful however, because rm permanently removes something. You must be absolutely certain you are using it properly.

Now let's say you want to display a small file's contents. For that you can use the cat command.

$ cat a.txt

You can also use less to read a file (and press q to quit from it).

$ less b.txt

Sometimes you may run a command and be told that you do not have permission to either read from, write to, or execute that file. If your user has the power to use sudo then you may be able to interact with that file after all. sudo is a way of granting yourself higher permissions, but you must be careful when using it, as it could lead to disastrous consequences if you, for example, delete or overwrite an important system file.

next page