Basic Commands Table
cd | Change directory |
ls | Directory listing |
ls -al | Formatted listing with hidden files included. |
cd dir | Change directory to dir |
pwd | Print working directory |
mkdir dir1 dir2 | Creates directory dir1 and dir2 |
rm file | Delete file |
cp file1 file 2 | Copy file1 to file2 |
mv file1 file2 | Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2. |
ps | Displays all currently active processes |
top | Displays all running processes |
kill pid | Kills process id pid |
bg | Lists stopped or background jobs |
chmod octal file | Change the permissions of a file to octal, which can be found separately for user, group, and world (see below) |
ssh user@host | Connect to a host as a specified user |
ssh -p port user@host | Connect to a host on target port as a specified user |
ping host | Ping target host and output results |
whois domain | Get whois information for a target domain |
dig domain | Get DNS information for a target domain |
dig -x host | Reverse lookup for target host |
tar cf file.tar files | Create a tar named file.tar containing files |
tar xf file.tar | Extract the files from file.tar |
tar czf file.tar.gz files | Create a tar file Gzip compression |
tar xzf file.tar.gz / gunzip file.tar.gz | Extract a tar using Gzip |
tar cjf file.tar.bz2 | Create a tar using Bzip2 compression |
tar xjf file.tar.bz2 | Extract a tar using Bzip2 |
gzip file | Compresses a file and renames it to file.gz |
gzip -d file.gz | Decompresses file.gz back to file |
whoami | Display who you are logged in as |
w | Display who is online |
finger user | Display information about user |
uname -a | Show kernel information |
cat /proc /cpuinfo | Display CPU information |
cat /proc /meminfo | Display memory information |
man command | Show the manual for specified command |
df | Show disk usage |
whereis app | Show possible locations of app |
locate file | Find all instances of file |
grep pattern files | Search for a pattern in files |
grep -r pattern dir | Search recursively for a pattern in dir |
command | grep pattern | Search for a pattern in the output of command |
Directories
The 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.
Permissions

chmod
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 man chmod
.
chown
The command 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.
Type chown --help | more
for the onscreen manual that’ll explain the purpose of this command.
chgrp
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
.
ls -al
-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.