Skip to content

Common Linux commands ​

Replace example file and directory names with your actual paths.

Directories ​

CommandAction
pwdPrint current directory
lsList directory entries
ls -lhDetailed listing with readable sizes
ls -aInclude hidden entries
cd DIREnter a directory
cd ..Go to parent directory
cd ~Go home
mkdir DIRCreate a directory
mkdir -p a/b/cCreate nested directories
bash
pwd
ls -lh
mkdir -p project/data
cd project

Copy, move, and delete ​

CommandAction
cp SOURCE DESTCopy a file
cp -r SOURCE DESTCopy a directory
mv SOURCE DESTMove or rename
rm FILEDelete a file
rm -r DIRDelete a directory and its contents
bash
cp input.txt input.bak
mv result.txt results/result.txt
rm temp.txt

Check before deleting

Files removed with rm are generally not recoverable through a simple undo. Verify the current and target paths before deleting.

View files ​

CommandAction
cat FILEPrint the entire file
less FILEPage through a file; press q to quit
head FILEFirst 10 lines
head -n 20 FILEFirst 20 lines
tail FILELast 10 lines
tail -f FILEFollow appended log output
wc -l FILECount lines
bash
head -n 5 input.txt
tail -f job.out
wc -l samples.txt

Find files and text ​

CommandAction
find . -name "*.txt"Find matching filenames below the current directory
find . -type fFind regular files recursively
grep "TEXT" FILEFind matching text
grep -n "TEXT" FILEInclude line numbers
grep -r "TEXT" DIRSearch recursively
bash
find . -name "*.log"
grep -n "error" job.out

Archives ​

CommandAction
tar -czf data.tar.gz data/Create a gzip-compressed archive
tar -xzf data.tar.gzExtract it
zip -r data.zip data/Create a ZIP archive
unzip data.zipExtract ZIP
bash
tar -czf results.tar.gz results/
tar -xzf results.tar.gz

Permissions ​

CommandAction
ls -lShow permissions, owner, and size
chmod +x script.shAdd executable permission
chmod 600 FILEOwner read/write only
chmod 644 FILEOwner read/write; others read-only
bash
ls -l run.sh
chmod +x run.sh
./run.sh

Disk usage ​

CommandAction
df -hFilesystem capacity and free space
du -sh DIRTotal directory usage
du -h --max-depth=1Usage one level below the current directory
ls -lhFile sizes
bash
du -sh project
du -h --max-depth=1
df -h

Processes ​

ps -u $USER lists your processes; top monitors processes interactively; kill PID signals a process to terminate.

bash
ps -u $USER
kill 12345

Use the scheduler for long computations. Login nodes are for brief checks and file management.

Text editors ​

nano ​

bash
nano run.sh

Ctrl+O saves, Enter confirms the filename, and Ctrl+X exits.

vim ​

bash
vim run.sh

Press 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:

bash
mkdir -p ~/project/data ~/project/scripts ~/project/results
cd ~/project

Follow job output or error logs:

bash
tail -f job.out
tail -f job.err

Archive results:

bash
tar -czf results.tar.gz results/

Find large directories and files:

bash
du -h --max-depth=1
ls -lh

Prefer 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.

Copyright 2021 Biodesign Center. All rights reserved.