You are on page 1of 3

Linux Command Line Essentials

Basic shell
cd D
ls al
mv A B
cp A B
chmod u+x F
rm F
rmdir D
rm rf D
mkdir D
cat F
less F
grep EXP F
man C

Change the current directory to D

Print the current directory
Gives a list of filenames in the current directory
Gives a bit more information about files in the current directory
Rename file A to B
Copy content of file A into file B
Give execute permission on file F
Remove file F
Remove directory D. The directory must be empty.
Delete directory D including all files and subdirectories.
Create new directory
Display file
Display file using a pager
Search for the EXP expression into file F
Get help about command C

The shell provides some specific characters:

2> F
cmd1 | cmd1


Is replaced by all files in the directory

Is replaced by any filename starting with Test
Is replaced by any filename starting with Test with an
additional character
Is replaced by the value of the XYZ variable
Redirect the output of the command to file F
Redirect the error output of the command to file F
Redirect the input of the command from file F
Redirect the errors to the standard output
Pipe the output of cmd1 in the input of the cmd2
Use simple quote to avoid the shell to interpret the
Current directory
Upper directory
Home directory of user tr1

Environment variables
The user can define environment variables.
X=test testy
export X=test

Assign string test to $X

Assign string test testy to $X. The double quotes are
needed because of the space character.
Assign string test to $X. The variable is exported, so it
will be visible in child processes.

Some variables are predefined and have special meaning:


Contains the path of all directories the shell will scan to

find executables.
Contains the path of all directories the dynamic linker
will scan to find the shared libraries.

export PATH=.:/usr/bin:/bin
Set the PATH variable the shell will search the executables first in the current
directory, then in /usr/bin, and them in /bin. The PATH variable will be inherited in all
child processes.

Processes are identified by their process id (pid). It is an integer value between 1 and
ps -eaf
ps eaf | grep $USER
kill -9 PID

List all processes in the system

List only your own processes
Monitor running processes
Kill brutally process PID

Other useful commands

tar xvf F
gunzip F
vi F
find . name F
du k .
df k
df k .

Unarchive files from archive F

Uncompress file F
Edit file F (see below)
Find recursively file name F starting in the current
See how disk space the current directory takes
Display all filesystems including remote ones
Display filesystem of the current directory

pmap PID
g++ -c test.cpp
gmake 2>&1 | less
gdb test
gdb test core_file

Look the memory mapped zones (including shared

libraries) of process PID
Compile C++ file test.cpp
Launch a compilation via GNUmake
Launch a compilation with a pager to be used when
there are a lot of error messages.
Debug program test with the GNU debugger
Examine a core dump file generated by program test

Vi editor
:set list

By: Its FOSS

Save the file and quit

Quit without saving the file
Insert starting left of the cursor
Append starting right of the cursor
Exit insert/append mode
Move cursor
Search string test
Search next occurrence
Delete character under the cursor
Delete line under the cursor
Undo last change
Beginning of the file
Go to line n
End of the file
Beginning of the line
End of the line
See special characters in the file
Copy the line into the buffer
Copy 5 lines into the buffer
Paste buffer after the current line