Common Linux commands
Replace example file and directory names with your actual paths.
Directories
| Command | Action |
|---|---|
pwd | Print current directory |
ls | List directory entries |
ls -lh | Detailed listing with readable sizes |
ls -a | Include hidden entries |
cd DIR | Enter a directory |
cd .. | Go to parent directory |
cd ~ | Go home |
mkdir DIR | Create a directory |
mkdir -p a/b/c | Create nested directories |
pwd
ls -lh
mkdir -p project/data
cd projectCopy, move, and delete
| Command | Action |
|---|---|
cp SOURCE DEST | Copy a file |
cp -r SOURCE DEST | Copy a directory |
mv SOURCE DEST | Move or rename |
rm FILE | Delete a file |
rm -r DIR | Delete a directory and its contents |
cp input.txt input.bak
mv result.txt results/result.txt
rm temp.txtCheck before deleting
Files removed with rm are generally not recoverable through a simple undo. Verify the current and target paths before deleting.
View files
| Command | Action |
|---|---|
cat FILE | Print the entire file |
less FILE | Page through a file; press q to quit |
head FILE | First 10 lines |
head -n 20 FILE | First 20 lines |
tail FILE | Last 10 lines |
tail -f FILE | Follow appended log output |
wc -l FILE | Count lines |
head -n 5 input.txt
tail -f job.out
wc -l samples.txtFind files and text
| Command | Action |
|---|---|
find . -name "*.txt" | Find matching filenames below the current directory |
find . -type f | Find regular files recursively |
grep "TEXT" FILE | Find matching text |
grep -n "TEXT" FILE | Include line numbers |
grep -r "TEXT" DIR | Search recursively |
find . -name "*.log"
grep -n "error" job.outArchives
| Command | Action |
|---|---|
tar -czf data.tar.gz data/ | Create a gzip-compressed archive |
tar -xzf data.tar.gz | Extract it |
zip -r data.zip data/ | Create a ZIP archive |
unzip data.zip | Extract ZIP |
tar -czf results.tar.gz results/
tar -xzf results.tar.gzPermissions
| Command | Action |
|---|---|
ls -l | Show permissions, owner, and size |
chmod +x script.sh | Add executable permission |
chmod 600 FILE | Owner read/write only |
chmod 644 FILE | Owner read/write; others read-only |
ls -l run.sh
chmod +x run.sh
./run.shDisk usage
| Command | Action |
|---|---|
df -h | Filesystem capacity and free space |
du -sh DIR | Total directory usage |
du -h --max-depth=1 | Usage one level below the current directory |
ls -lh | File sizes |
du -sh project
du -h --max-depth=1
df -hProcesses
ps -u $USER lists your processes; top monitors processes interactively; kill PID signals a process to terminate.
ps -u $USER
kill 12345Use the scheduler for long computations. Login nodes are for brief checks and file management.
Text editors
nano
nano run.shCtrl+O saves, Enter confirms the filename, and Ctrl+X exits.
vim
vim run.shPress i to insert text and Esc to leave insert mode. Use :wq to save and quit, or :q! to quit without saving.
Common workflows
Create a project layout:
mkdir -p ~/project/data ~/project/scripts ~/project/results
cd ~/projectFollow job output or error logs:
tail -f job.out
tail -f job.errArchive results:
tar -czf results.tar.gz results/Find large directories and files:
du -h --max-depth=1
ls -lhPrefer letters, digits, underscores, and hyphens in filenames. Check pwd and ls before important file operations. Read .out, .err, and application logs when scripts fail. Use COMMAND --help when unsure about an option.
