0% found this document useful (0 votes)
309 views

Linux Command Line Cheat Sheet Its FOSS PDF

This document provides a summary of basic Linux shell commands, environment variables, processes, and other useful commands. It also covers the vi text editor. Some key commands include cd to change directories, ls to list files, grep to search files, and kill to terminate processes. Environment variables like PATH and LD_LIBRARY_PATH determine program locations. Processes are identified by PIDs and monitored using ps and top. The vi editor is used to create and edit files using modes, searches, and text manipulation commands.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
309 views

Linux Command Line Cheat Sheet Its FOSS PDF

This document provides a summary of basic Linux shell commands, environment variables, processes, and other useful commands. It also covers the vi text editor. Some key commands include cd to change directories, ls to list files, grep to search files, and kill to terminate processes. Environment variables like PATH and LD_LIBRARY_PATH determine program locations. Processes are identified by PIDs and monitored using ps and top. The vi editor is used to create and edit files using modes, searches, and text manipulation commands.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Linux Command Line Essentials

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

The shell provides some specific characters:

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.

X=test Assign string test to $X


X=test testy Assign string test testy to $X. The double quotes are
needed because of the space character.
export X=test 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 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

Other useful commands


Commands
tar xvf F Unarchive files from archive F
gunzip F Uncompress file F
vi F Edit file F (see below)
find . name F Find recursively file name F starting in the current
directory.
du k . See how disk space the current directory takes
df k Display all filesystems including remote ones
df k . Display filesystem of the current directory
pmap PID Look the memory mapped zones (including shared
libraries) of process PID
g++ -c test.cpp Compile C++ file test.cpp
gmake Launch a compilation via GNUmake
gmake 2>&1 | less Launch a compilation with a pager to be used when
there are a lot of error messages.
gdb test Debug program test with the GNU debugger
gdb test core_file Examine a core dump file generated by program test

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

By: Its FOSS

You might also like