terminal

root@cheat

Filtering by:filescloseClear

tar -xzvf

Extract a compressed gzip archive. Decompresses and extracts files from a tar.gz file.

$ tar -xzvf archive.tar.gz -C /destination/ tar -xvf archive.tar
files

tar -czvf

Create a compressed gzip archive. Combines multiple files/folders into a single compressed file.

$ tar -czvf backup.tar.gz /home/user/ tar -cvf archive.tar folder/
files

tail -f

Display the last lines of a file and follow new additions. -f flag follows the file in real-time.

$ tail -n 50 /var/log/syslog tail -f /var/log/nginx/access.log
filessystem

head

Display the first lines of a file. Default shows first 10 lines, -n specifies number of lines.

$ head -n 5 /etc/passwd head -c 100 file.txt
filesbeginner

less

View file contents page by page. Allows scrolling through large files with keyboard navigation.

$ less /var/log/auth.log less +F /var/log/syslog
files

cat

Display file contents. Concatenate and display files to standard output.

$ cat file.txt cat file1.txt file2.txt > combined.txt
filesbeginner

touch

Create an empty file or update file timestamps. If the file exists, updates its modification time.

$ touch newfile.txt touch -d '2024-01-01' file.txt
filesbeginner

rmdir

Remove empty directories. Only works on directories that contain no files.

$ rmdir /tmp/empty_dir
files

mkdir -p

Create directories including parent directories. The -p flag creates parent directories as needed.

$ mkdir -p /var/www/html/assets/css
filesbeginner

mv

Move or rename files and directories. Can move files between directories or rename them.

$ mv old_name.txt new_name.txt mv file.txt /home/user/
files

cp -r

Copy files or directories recursively. The -r flag copies directories and their contents.

$ cp -r /home/user/docs/ /backup/
files

cd

Change the current directory. Navigate to different folders in the file system.

$ cd /var/log cd ~ cd ..
filesbeginner

pwd

Print the current working directory path. Shows the full path of where you are in the file system.

$ pwd # Output: /home/user/documents
filesbeginner

rm -rf

Forcefully remove files and directories recursively. USE WITH EXTREME CAUTION!

WARNING: rm -rf /tmp/old_files
Dangerousfiles

find

Find files by name in a directory tree

$ find . -name '*.log' -mtime -7
searchfiles

grep

Search for text patterns recursively in files

$ grep -r 'error' /var/log/
searchfiles

ls

List all files including hidden ones with detailed information

$ ls -la /home/user
filesbeginner