Basic Linux Commands
This page lists basic Linux commands that are useful for new users.
1 Where am I?
Show the current directory:
pwd2 List files
lsShow details:
ls -lhShow hidden files:
ls -la3 Change directory
Go to a folder:
cd folder_nameGo back to your home directory:
cdGo up one level:
cd ..4 Create folders
mkdir projectCreate nested folders:
mkdir -p project/data/raw5 Copy files
Copy one file:
cp file.txt backup.txtCopy a folder:
cp -r project project_backup6 Move or rename files
Rename a file:
mv old_name.txt new_name.txtMove a file into a folder:
mv file.txt project/7 Delete files
Delete a file:
rm file.txtDelete a folder and everything inside it:
rm -r folder_nameBe careful with rm. Files deleted from the command line may not be recoverable.
8 View text files
Show a whole file:
cat file.txtView a long file page by page:
less file.txtShow the first lines:
head file.txtShow the last lines:
tail file.txtWatch a file as it updates:
tail -f output.log9 Edit text files
Use nano for simple editing:
nano script.RSave with Ctrl + O, then press Enter. Exit with Ctrl + X.
10 Search inside files
Search for text in a file:
grep "error" output.logSearch recursively in a folder:
grep -r "parameter" .11 Find files
Find files by name:
find . -name "*.R"Find large files:
find . -type f -size +1G12 Check disk space
df -hCheck the size of a folder:
du -sh folder_name13 Check memory
free -h14 Check running processes
topor, if installed:
htop15 Stop a running command
Press:
Ctrl + C
16 Command history
Show previous commands:
historySearch command history:
Ctrl + R
17 Useful shortcuts
| Shortcut | Meaning |
|---|---|
Tab |
autocomplete file or command name |
Ctrl + C |
stop current command |
Ctrl + L |
clear screen |
Ctrl + A |
move to start of line |
Ctrl + E |
move to end of line |