Change Directory
cd [directory]cd /var/log
cd ~
cd ..
cd -Note cd with no argument returns to your home directory. cd - switches to the previous directory you were in, which is great for toggling between two locations.
Bash & Linux · 11 entries
cd [directory]cd /var/log
cd ~
cd ..
cd -Note cd with no argument returns to your home directory. cd - switches to the previous directory you were in, which is great for toggling between two locations.
ls [options] [directory]ls -la /etc
ls -lhS ~/Downloads
ls -lt --color=autodrwxr-xr-x 5 deploy staff 160 Mar 12 09:14 config
-rw-r--r-- 1 deploy staff 2.4K Mar 11 18:30 app.jsNote -l for long format, -a includes hidden files (dotfiles), -h for human-readable sizes, -S sorts by size, -t sorts by modification time (newest first), -R lists recursively.
pwd [-P]pwd/home/deploy/projects/web-appNote Use -P to resolve symlinks and show the physical path rather than the logical one.
mkdir [options] directory...mkdir -p src/components/auth
mkdir -m 750 secretsNote -p creates the full path including any missing parent directories and will not error if the directory already exists. -m sets permissions at creation time.
cp [options] source destinationcp config.yml config.yml.bak
cp -r templates/ /opt/app/templates/
cp -i report.csv ~/Desktop/Note -r is required for directories (recursive copy). -i prompts before overwriting. Without -i, cp silently overwrites the destination. Use -a to preserve permissions, timestamps, and symlinks.
mv [options] source destinationmv old_name.js new_name.js
mv *.log /var/archive/
mv -i data.db /backups/Note mv both renames and relocates. It silently overwrites the target by default. Use -i to prompt before overwriting or -n to never overwrite.
rm [options] file...rm debug.log
rm -r old_build/
rm -ri temp_data/Note WARNING: rm is permanent. There is no trash can. -r removes directories recursively, -f forces removal without prompts. Never run rm -rf / or rm -rf * without double-checking your current directory with pwd first. Use -i for interactive confirmation on important files.
touch [options] file...touch index.html
touch -t 202601151030 report.pdfNote If the file exists, touch updates its modification timestamp without changing content. With -t, you can set a specific timestamp in [[CC]YY]MMDDhhmm[.ss] format.
find [path] [expression]find /var/log -name '*.log' -mtime -7
find . -type f -size +100M
find src/ -name '*.ts' -exec wc -l {} +/var/log/syslog
/var/log/auth.logNote -name is case-sensitive; use -iname for case-insensitive. -mtime -7 means modified in the last 7 days. -exec runs a command on each result; use + instead of \; to batch them for better performance.
tree [options] [directory]tree -L 2 --dirsfirst
tree -I 'node_modules|.git' -a.
├── src/
│ ├── index.ts
│ └── utils/
├── package.json
└── tsconfig.jsonNote -L limits depth, -I excludes patterns (pipe-separated), -a shows hidden files, --dirsfirst groups directories at the top. Not installed by default on all systems; install via your package manager.
ln [options] target link_nameln -s /opt/app/current/config.yml ~/config.yml
ln -sf /usr/bin/python3 /usr/local/bin/pythonNote Without -s, a hard link is created (shares the same inode; cannot span filesystems). Symbolic links (-s) are like shortcuts and can point anywhere, including directories. -f replaces an existing link.