The examples in this document assume that you are using a POSIX-compliant (such as bash, sh, zsh, ksh) shell.
Large portions of GNU/Linux functionality are achieved using the terminal. Most distributions of Linux include terminal emulators that allow users to interact with a shell from their desktop environment. A shell is a command-line interpreter that executes user inputted commands. Bash (Bourne Again SHell) is a common default shell among many Linux distributions and is the default shell for macOS.
These shortcuts will work if you are using Bash with the emacs keybindings (set by default):
bg
command allowing that process to run in the background. To again bring that process to foreground, use fg
command. To view all background processes, use jobs
command.Alternatively, you can switch to the vi keybindings in bash using set -o vi
. Use set -o emacs
to switch back to the emacs keybindings.
Linux has a command for almost any tasks and most of them are intuitive and easily interpreted.
Getting Help in Linux
Command | Usability |
---|---|
man <name> | Read the manual page of <name>. |
man <section> <name> | Read the manual page of <name>, related to the given section. |
man -k <editor> | Output all the software whose man pages contain <editor> keyword. |
man -K <keyword> | Outputs all man pages containing <keyword> within them. |
apropos <editor> | Output all the applications whose one line description matches the word editor. When not able to recall the name of the application, use this command. |
help | In Bash shell, this will display the list of all available bash commands. |
help <name> | In Bash shell, this will display the info about the <name> bash command. |
info <name> | View all the information about <name>. |
dpkg -l | Output a list of all installed packages on a Debian-based system. |
dpkg -L packageName | Will list out the files installed and path details for a given package on Debian. |
dpkg -l | grep -i <edit> | Return all .deb installed packages with <edit> irrespective of cases. |
less /var/lib/dpkg/available | Return descriptions of all available packages. |
whatis vim | List a one-line description of vim. |
<command-name> --help | Display usage information about the <tool-name>. Sometimes command -h also works, but not for all commands. |
User identification and who is who in Linux world
Command | Usability |
---|---|
hostname | Display hostname of the system. |
hostname -f | Displays Fully Qualified Domain Name (FQDN) of the system. |
passwd | Change password of current user. |
whoami | Username of the users logged in at the terminal. |
who | List of all the users currently logged in as a user. |
w | Display current system status, time, duration, list of users currently logged in on system and other user information. |
last | Who recently used the system. |
last root | When was the last time root logged in as user. |
lastb | Shows all bad login attempts into the system. |
chmod | Changing permissions - read,write,execute of a file or directory. |
Process related information
Command | Usability |
---|---|
top | List all processes sorted by their current system resource usage. Displays a continually updated display of processes (By default 3 seconds). Use q key to exit top. |
ps | List processes currently running on current shell session |
ps -u root | List all of the processes and commands root is running |
ps aux | List all the processes by all users on the current system |
Linux uses some conventions for present and parent directories. This can be a little confusing for beginners.
Whenever you are in a terminal in Linux, you will be in what is called the current working directory. Often your command prompt will display either the full working directory, or just the last part of that directory. Your prompt could look like one of the following:
user@host ~/somedir $
user@host somedir $
user@host /home/user/somedir $
which says that your current working directory is /home/user/somedir
.
In Linux ..
represents the parent directory and
.
represents the current directory.
Therefore, if the current directory is /home/user/somedir
, then cd ../somedir
will not change the working directory.
The table below lists some of the most used file management commands
Command | Utility |
---|---|
pwd | Get the full path of the current working directory. |
cd - | Navigate to the last directory you were working in. |
cd ~ or just cd | Navigate to the current user's home directory. |
cd .. | Go to the parent directory of current directory (mind the space between cd and .. ) |
Command | Utility |
---|---|
ls -l | List the files and directories in the current directory in long (table) format (It is recommended to use -l with ls for better readability). |
ls -ld dir-name | List information about the directory dir-name instead of its contents. |
ls -a | List all the files including the hidden ones (File names starting with a . are hidden files in Linux). |
ls -F | Appends a symbol at the end of a file name to indicate its type (* means executable, / |