Bash Basic Commands
- Let’s learn
Bashbasic commands for day to day work. - We also call it Linux commands, or Terminal commands
Check your current working directory
Section titled “Check your current working directory”pwdstandsprint working directory
pwdGoto home directory
Section titled “Goto home directory”cdstands forchange directory~Tilde stands for default home directory
cd ~Change directory
Section titled “Change directory”iwork/learnis a relative path where we want to go after change directory
cd iwork/learnList all files/folders
Section titled “List all files/folders”lsstands for list directory
lsMake new directory
Section titled “Make new directory”mkdirstands forMake Directory
mkdir <directory_name>Remove directory
Section titled “Remove directory”rmstands forremove-rfare optionsrrecursivefforce,
rm -rf <directory_name>- Above command means delete the folder and all its files and sub folders recursively and don’t ask for permission hence
forceused
Essential Bash Commands for Daily Use
Section titled “Essential Bash Commands for Daily Use”| Command | Description | Example |
|---|---|---|
ls | List directory contents | ls -la |
cd | Change directory | cd ~/Documents |
pwd | Print working directory | pwd |
mkdir | Create a new directory | mkdir new_folder |
rm | Remove files/directories | rm file.txt |
cp | Copy files/directories | cp file.txt backup/ |
mv | Move/rename files | mv old.txt new.txt |
cat | Display file content | cat file.txt |
grep | Search text patterns | grep "search" file.txt |
find | Search for files | find . -name "*.txt" |
chmod | Change file permissions | chmod +x script.sh |
ps | Display running processes | ps aux |
kill | Terminate processes | kill 1234 |
top | Display system processes | top |
df | Disk space usage | df -h |
du | Directory space usage | du -sh * |
head | Show first lines of file | head -n 10 file.txt |
tail | Show last lines of file | tail -f log.txt |
wc | Word count | wc -l file.txt |
tar | Archive files | tar -czf archive.tar.gz folder/ |
ssh | Secure shell connection | ssh user@host |
scp | Secure copy | scp file.txt user@host:/path/ |
history | Command history | history | grep ssh |
man | Manual pages | man ls |
echo | Display message | echo "Hello" |
export | Set environment variable | export PATH=$PATH:/new/path |