Linux commands

echo $PATH = will show all executable commands path available.
export PATH=$PATH:/home/dir/dir = will add this path to the executable path available
which “name” = will show the path of the executable “name”
man = get in deep help on any commands
“command” –help = info about the command


ps = list process
htop ( see options )

Data Stream

“>,<” = redirect IN OR OUT OR ERR data stream
<< or >> = append

example :
grep -r “haha” | cat > output.txt   = this will return the output to a single file output.txt

Files System
~# = Home directory ( /home )
pwd = show absolute path

lrwxrwxrwx can be read like this : l|wxr|wxr|wxr   so type| 1st group “user” | 2nd group “group” | 3rd group “others”
– = file
d = directory
l = links
r = read
w = write
x = able to cd in

Directories :
etc = configuration files
bin = executable
sbin = system executable

mkdir = make directory,  -p with sub directories
rm -r = remove directory, -f would force it

Files :
touch = create empty file
nano, vim, vi = create/edit file
echo “hello” > file.txt = will create a file with hello texte in it
rm = remove file
head =  read 10 1st line of a file, -n can be use to specified the number of lines required
tail = read last 10 lines of a file, -n can be use to specified the number of lines required, -f is use to monitor live change to that file.
more = read file with % per page

Filtering :
grep = filtering command
ls -l | grep hostname
you can use it to filter output too :
ls -l | grep ^l = would return only links files

Links, Hard vs Soft :
soft link are pointer to specific file
hard link are file that have the same inode, size, date
ln -s file.txt file.soft.txt = soft link
ln  file.txt file.soft.txt = hard link
the difference between soft and hard link is that soft link is a path file so if the file is deleted you lose the access to it. Hard link will create a duplicate of the file and keep it identical. if the original file get deleted you still have access to the hard link one.

Search operation :
find = command to search for
find / = with absolute path
man to see all different option
example : find . -name “*.txt”
Piping exemple :
find / -name kernel -type d -exec ls -l –color {} \;

Compression :
tar -cf archive.tar ~ = archive all file in current dir
tar -tf archive.tar = read the archive
gzip archive.tar = compress the file
tar -czf archive.tar ~ = archive and compress all file in current dir
tar -xvzf / archive.tar.gz = uncompress

Sorting :
sort -n numbers.txt > sorted.txt

User Management :
useradd –help
useradd patrick
su patrick
passwd patrick
enter pass
userdel patrick
useradd -m patrick
adduser patrick2

Changing ownership of a file or dir  :
chown –help
Changing permission of a file or dir  :
chmod –help

Executable files and scripts  : = shell file / bash shell
chmod u+x

exemple : nano
echo “this is a test”

execute : ./

Environement variables  :


export MY_VAR=patrick
echo $MY_VAR
chmod +x

Filename creation  :
example :
actions > /Path/$(uname -n)_Description_$now.txt

Leave a Comment