Basic commands of Bash Terminal
List files and directories:
ls
: List files and directories.
ls -a
: List files and directories, including hidden ones.
List files and directories with full details:
ls -l
: List files and directories with full details.
Get file size in GB/MB:
ls -l --b=M
ls -l --b=G
List files and directories with full details, including hidden files:
ls -la
or
ls -al
: List files and directories with full details, including hidden files.
Change directory:
cd <directory name>
: Change to the specified directory. Autocomplete is available by typing a few letters of the directory name.
Go to the previous directory:
cd ..
: Go to the previous directory.
Go to the home directory:
cd
cd ~
: Go to the home directory.
Changing back and forth:
pushd <directory>
popd
Read file info:
file <file>
Search for file and folder:
locate <search>
Before using the locate command, make sure to upgrade the database of the directory and file list:
sudo updatedb
Find out if a file/folder exists:
which <search>
History of the last 1000 commands:
history
Get help about a command:
whatis <command>
Example: whatis cal
Make directory:
mkdir <name>
Create file:
touch <file name>
If the file doesn't exist, it will be created. If it does exist, the modified date will be updated.
Create multiple files:
touch <filename> <filename> <filename>
Copy file:
cp <old address> <new address>
Move file:
mv <old address> <new address>
Rename file:
mv <old name> <new name>
Remove all files from a directory:
rm *
rm <filename>*
Remove folder and its contents:
rm -r <folder name>
rm -r *
Remove empty folders:
rmdir <folder name>
Clear the command line:
clear
Read the contents of a file:
cat <filename>
Add content to a text file:
cat >> <filename>
Type the text to save and use Ctrl+C/V to exit.
Read through a file:
more <filename>
less <filename>
Press 'q' to exit.
Edit a file:
nano <filename>
Read through command history:
history | less
Save command output to a file:
history > his.txt
ls -la > lsout.txt
Login as administrator:
sudo -s
The dollar sign turns into a hashtag.
Exit administrator mode:
exit
See file permissions:
ls -l
The output format is: `-rw- r-- r--`, where the first part represents permissions for the user, the second for the group, and the third for everybody.
Set file permissions:
Nobody can read: chmod 700 <filename>
Everybody can only read: chmod 744 <filename>
Standard permission for files: 644
Standard permission for folders: 755
Check system memory:
watch free -h