Linux Command Line Cheat Sheet Its FOSS PDF
Linux Command Line Cheat Sheet Its FOSS PDF
Basic shell
Commands
cd D Change the current directory to D
pwd Print the current directory
ls Gives a list of filenames in the current directory
ls al Gives a bit more information about files in the current directory
mv A B Rename file A to B
cp A B Copy content of file A into file B
chmod u+x F Give execute permission on file F
rm F Remove file F
rmdir D Remove directory D. The directory must be empty.
rm rf D Delete directory D including all files and subdirectories.
mkdir D Create new directory
cat F Display file
less F Display file using a pager
grep EXP F Search for the EXP expression into file F
man C Get help about command C
Character
* Is replaced by all files in the directory
Test* Is replaced by any filename starting with Test
Test? Is replaced by any filename starting with Test with an
additional character
$XYZ Is replaced by the value of the XYZ variable
>F Redirect the output of the command to file F
2> F Redirect the error output of the command to file F
<F Redirect the input of the command from file F
2>&1 Redirect the errors to the standard output
cmd1 | cmd1 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
~tr1 Home directory of user tr1
Environment variables
The user can define environment variables.
PATH Contains the path of all directories the shell will scan to
find executables.
LD_LIBRARY_PATH 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 List all processes in the system
ps eaf | grep $USER List only your own processes
top Monitor running processes
kill -9 PID Kill brutally process PID
Vi editor
Commands
:x Save the file and quit
:q! Quit without saving the file
i Insert starting left of the cursor
a Append starting right of the cursor
ESC Exit insert/append mode
arrows Move cursor
/test Search string test
n Search next occurrence
x Delete character under the cursor
dd Delete line under the cursor
u Undo last change
:0 Beginning of the file
:n Go to line n
G End of the file
^ Beginning of the line
$ End of the line
:set list See special characters in the file
yy Copy the line into the buffer
5yy Copy 5 lines into the buffer
p Paste buffer after the current line