Basic Commands Table
|Formatted listing with hidden files included.|
|Change directory to dir|
|Print working directory|
|Creates directory dir1 and dir2|
|Copy file1 to file2|
|Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2.|
|Displays all currently active processes|
|Displays all running processes|
|Kills process id pid|
|Lists stopped or background jobs|
|Change the permissions of a file to octal, which can be found separately for user, group, and world (see below)|
|Connect to a host as a specified user|
|Connect to a host on target port as a specified user|
|Ping target host and output results|
|Get whois information for a target domain|
|Get DNS information for a target domain|
|Reverse lookup for target host|
|Create a tar named file.tar containing files|
|Extract the files from file.tar|
|Create a tar file Gzip compression|
|Extract a tar using Gzip|
|Create a tar using Bzip2 compression|
|Extract a tar using Bzip2|
|Compresses a file and renames it to file.gz|
|Decompresses file.gz back to file|
|Display who you are logged in as|
|Display who is online|
|Display information about user|
|Show kernel information|
|Display CPU information|
|Display memory information|
|Show the manual for specified command|
|Show disk usage|
|Show possible locations of app|
|Find all instances of file|
|Search for a pattern in files|
|Search recursively for a pattern in dir|
|Search for a pattern in the output of command|
mkdir (make directory) command requires administrative privileges. Directories can be created in batches by entering the directories in one command. As an example, to make the directories: “arabica” and “robusta” you can execute the command
mkdir arabica robusta. The full path must be entered or both directories will be created in the current directory. For example,
mkdir arabica creates the arabica directory in the current directory, whereas
mkdir /usr/arabica will create arabica in the /usr directory regardless of your current directory.
There are a few different options for the mkdir command that are pretty common. The -p option creates all parent directories if they do not already exist. The -v option sets the output to print for each created directory. The -m option enables the user to set permissions for the directory as it is created. For example, in octal mode,
mkdir -m 777 /usr/arabica/Caturra will enable owner, group, and world to read, write, and execute permissions to the Caturra directory.
The symbol to grant permissions is (+) and the symbol to remove permissions is (-). For example, to give a group permission to read, write, and execute on the /usr/arabica/Bourbon/Caturra directory, run the following command:
chmod g+rw /usr/arabica/Bourbon/Caturra.
Permissions can also be changed using octal modes. Octal modes are numeric representations of permisions. read = 4, write = 2, and execute = 1. So if you wanted to give someone full read, write and execute permissions, use the number 7 (4+2+1). To give read and write permissions only, use 6 (4+2). To give read only permissions, use 4. Octal mode also requires a number for each role (user, group, other users). For example, to give the user read, write, and execute permission to the /usr/arabica/Bourbon/Caturra directory, run the following command:
chmod 740 /usr/arabica/Bourbon/Caturra.
To remove (-) the ability of all users (o) to read (r) and execute (x) files in the Caturra directory:
sudo chmod o-rx Caturra [notice this is a relative path (as opposed to an absolute, or full path) command using sudo to elevate privileges].
Likewise, to remove (-) the ability of group members (g) to read (r) and execute (x) files in the Caturra directory:
sudo chmod g-rx Caturra.
Further octal examples:
chmod 777 – read, write, and execute for all.
chmod 755 – rwx for owner, rx for group, and world. For further info, see
chown is used to change the owner and/or group of a file. The user and group can be changed at the same time, by using either the . or : symbols. For this next example, let’s use the colon symbol (:). To change both the owner (to Catuai) and the group (to Typica) of the /usr/arabica/yellow directory at the same time, we can execute the following command:
chown Catuai:Typica /usr/arabica/yellow. To change all of the files or directories under /usr/arabica directory, including yellow, type:
chown -R Catuai:Typica /usr/arabica. And finally, to change the group to Typica without changing the owner, simply type:
chown :Typica /usr/arabica. This doesn’t specify the owner name.
chown --help | more for the onscreen manual that’ll explain the purpose of this command.
chgrp (change group) command changes the group that has access to a file. The
chgrp command is similar to the
chown command, however,
chgrp can change only the group associated with a file or directory. To change the group owner of Caturra from root to the group huehuetenango:
sudo chgrp huehuetenango Caturra.
-rw-r–r– 1 root root 16 Sep 27 10:09 sl34.txt
The sample output text seen above shows a lot of useful information. Next to the filename (sl34.txt) shows the last time the file was modified: 10:09, followed by the date the file was last modified: Sep 27. The next item displayed is the size of the file (in bytes): 16. The group, root, and the owning user, root, follow. Next is the number of hard links to that location. In this case, it is 1. Finally, all the way to the left, is a reference to the file permissions that are represented by symbols.
File permissions either start with a dash (-) for files or the letter d (for directories). This example references a text file, so it begins with a dash. The next three symbols (rw-) represent the permissions assigned to users; those are read (r) and write (w), meaning the root user can read and write to this file. The second group of three symbols represent group permissions; here, all users in the root group are only permitted to read (r) the file. The last three symbols in the string represent the permissions for the world, or all other users; in this case, world users are permitted only to read (r) as well.