You are on page 1of 3

Linux Command Line Essentials

Basic shell
Commands
cd D
pwd
ls
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:


Character
*
Test*
Test?
$XYZ
>F
2> F
<F
2>&1
cmd1 | cmd1

.
..
~tr1

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
characters
Current directory
Upper directory
Home directory of user tr1

Environment variables
The user can define environment variables.
X=test
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:


PATH
LD_LIBRARY_PATH

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.

Example:
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
Processes are identified by their process id (pid). It is an integer value between 1 and
65535.
Commands
ps -eaf
ps eaf | grep $USER
top
kill -9 PID

List all processes in the system


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

Other useful commands


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
directory.
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
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
Commands
:x
:q!
i
a
ESC
arrows
/test
n
x
dd
u
:0
:n
G
^
$
:set list
yy
5yy
p

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