Frequently Used Command lines
kali</> diff file.txt #show the difference between two text files
kali</> ls -ltrs #my favorite option of ls
kali</> sort textfile #sort text by alphabetique order.
kali</> shotwell image.jpg #open an image file with shotwell.
kali</> bash or zsh #to switch temporarily between the bash and zsh
kali</> chsh -s /bin/bash #to switch permanently.
kali</> ls /abs/path/file #listing the content of a file.
kali</> file filename #show you the type of the file (jpg mp3..)
kali</> less filename #navigate in the text file
kali</> mv filename newfilename #rename file.
kali</> cp -r dirname destination #copy a directory
kali</> rm -r directory #remove directory recursivly
kali</> ls | tee file.txt #the tee command for two channels output (show and save ).
kali</> apropos tool #get information about the tools.
Bash :
if [ -X filename ]; then : -f .file exist, -e .file or dir exist, -z . is empty, -s: file is not empty (ctrl
structrs )
in rm or any command use *.extension to precise remove all file who termine with this extetion
e.g: rm *.txt #this will delet all files ended with .txt in the directory.
ls -l | tee text.txt #show the text and save it to the file
echo {1..20} #print from 1 to 20
$ #(not privilege user)
# #(previllige or superuser access)
echo $variable> textfilepath #save the content of the variable befor change it in a text file .
The hard link: is atached to the inode in hard disk and not
to original file even if it removed the hard link still exist
The soft link: is attached to the original file and depand to it
This makes it no longuer exist if the original file is removed.
The linux kernel
An operating system
- the kernel is the bridge between applications and hardware. It manages access to
the CPU, memory, and devices, making sure programs can use the hardware safely
and efficiently.
From what I've concluded, for the application to modify and react
with the system, it takes a sys call from sys library to connect
and modify the system according to the kernel.
PS1 VARIABLE CUSTOMIZATION
The prompt variable: is the first message that appears to you when you open the terminal
before the cursor… waiting for you to enter the command … it is VARIABLE customizable, and if
you want to reset it to default just type bash.
To customize it : Type : export PS1=’your_costom prompt’
File Permissions
●After enter the ls -l command :
- rwxrwxr-x 1 kali kali 78 Mar 15 21:09 script.sh
1) - / d : two probabilities - file or d directory exist more but rarely : l link c
caracter file b bloc fil
2) Using chmod in many format can edit file permissions
-Add or remove to a others all permission :
chmod o=rwx chmod o=
-Add to user and group in same command:
chmod u=rwx,g=w
-us - to remove permission
-write chmod +x filename ,don’t specify to apply to all users.
- by chmod 700 or 422… specify using numbers.
1 2 3 4 5 6 7
- rwxrwxr-x 1 kali kali 78 Mar 15 21:09 script.sh
1: the nature of the file : -/d/l…
2: the permissions
3: 1-> hard link number
4: owner of the rwx 1 and rwx 2.
5: the size of the file you can us -h to simplify it
6: the date
7: file name
The chown command
(change owner) just type : chown newowner filename
--- 0
--x 1
-w- 2
-wx 3
r-- 4
r-x 5 sudo -i = su
rw- 6 sudo adduser newusername : to create
rwx 7 new user
Environment Variables
Diff: They are a key-valus that stock and give the process and application the system
information to work.
●To show all environment variables just type set or env , to show all : set | more
●The Prompt Shell (PS) is also a variable.
Shell variables :
$PATH PATH environment variable used to look-up executables
(comands),
$PWD Present working directory.
$OLDPWD Previous working directory
$? Exit status of the last command.
$PS1 Primary command line prompt; see Using the PS* Variables
$RANDOM A pseudo random integer between 0 and 32767
$CPUTYPE Containe the archie of cpu and other information.
Change A Environment Variable:
●The environment variable contains strings for example $PS, for futur
changes
you should save his content in a text file to reset it if needed.
kali</> $PS>pscommand.txt
kali</> PS=’Kali/d$f’
kali</> export PS
export to save the change often in all environments.
●trying to add an executable (new hacking tool) to the $PATH variable :
kali</> PATH=$PATH:/root/newhackingtool
This assigns the original PATH variable plus the /root/newhackingtool
directory to the new PATH variable, so the variable contains everything it
did before, plus the new tool directory.
●To create your own variable :
kali</> VARNAME=”content” #alway the variables capitals
kali</> echo $VARNAME # output: content
Redirecting
Diff: it means sending the output or input of a command to a different place, like file
Instead of the terminal or from one command to another.
Append >> Turncate >
It like copy paste It like cut past
1. Create a specified file if it does not exist. 1. Create a specified file if it does not exist.
Append file (writing to new line)
2. 2. Remove file previous content.
3. Replace it by the new content.
●Stdout redirection:
cmnd>file.txt #truncate the input to file.txt
cmnd>>file.txt #append the input to file.txt
echo “text”>>file.txt #append the text to file.txt
●Stderr redirection:
cmnd 2>file.txt #2 is the file discrptor of stderr
cmnd 2>>file.txt #append the erreur to file.txt
●Both Error and Output: :
cmnd &>file.txt #truncate the both to the file.txt
cmnd >>file.txt 2>&1 #append the both to the file.txt
cmnd 1>file.txt 2>erreur.txt #truncate the stdout to file.txt and the stderr to erreur.txt
Piping
Diff: In Linux, piping (|) is used to send the output of one command as input to another
command. It allows for efficient data processing by chaining commands together.
The piping is do using “ | ” symbole
The grep is use with the pip for filtering data:
kali</> ls -a | grep Desktop
this line containe “Desktop”
kali</> cmnd >/dev/nul #send the output far away.