🏠 Home›Cheatsheets›Bash

🖥️ Bash Cheatsheet

Linux and Bash commands

Print Working Directory

Show current directory path

pwd

List Files

List files in directory

ls ls -la ls -lh

Change Directory

Navigate to different directory

cd /path/to/dir cd .. cd ~

Make Directory

Create new directory

mkdir directory_name mkdir -p path/to/dir

Create File

Create empty file

touch filename.txt cat > file.txt

Copy File

Copy file or directory

cp file.txt file_copy.txt cp -r directory/ copy_dir/

Move/Rename File

Move or rename file

mv oldname.txt newname.txt mv file.txt /path/to/dir/

Remove File

Delete file

rm filename.txt rm -f filename.txt

Remove Directory

Delete directory

rmdir empty_dir rm -r directory_name

View File Contents

Display file content

cat filename.txt less filename.txt more filename.txt

Edit File

Edit file in terminal

nano filename.txt vim filename.txt vi filename.txt

Search in Files

Find text pattern in files

grep "pattern" filename.txt grep -r "pattern" directory/

Find Files

Search for files by name

find . -name "filename.txt" find / -name "*.log"

Word Count

Count lines, words, characters

wc filename.txt wc -l filename.txt

Sort Lines

Sort file content

sort filename.txt sort -n numbers.txt

Unique Lines

Remove duplicate lines

uniq filename.txt sort filename.txt | uniq

Pipe Output

Send output to another command

cat file.txt | grep "pattern" ls | wc -l

Redirect Output

Save output to file

command > output.txt command >> output.txt

User Information

Show current user

whoami who id

Permissions

Change file permissions

chmod 755 filename chmod +x script.sh

Ownership

Change file owner

chown user filename chown user:group filename

Disk Space

Show disk usage

df -h du -sh directory/

Process List

Show running processes

ps ps aux top

Kill Process

Terminate process

kill PID kill -9 PID

More in this category

|🏠 Home|
|