Display Current User:
whoami
Get Current user UID - User ID, GID - Group Primary ID, Groups - Groups you belong too.
id
System Monitoring:
Install htop and run it.
sudo apt install htop
htop
htop displays your systems performance. At the bottom of htop shows how you can use htop such as : search, filter, kill, etc. To exit htop just press q.
Show your current directory:
pwd
Show path to home directory:
~
List directories and files in your current directory:
ls
Create empty a file
touch file.txt
Create file with text in it:
echo "Hello World" > file.txt
Create a hidden file using the . :
echo "This file is hidden" > .cantsee
Display all files even hidden ones:
ls -a
Create a copy of file:
cp myfile.txt myfilecopy.txt
Copy to another directory:
cp myfile.txt newdirectory/
Moving files and changing name:
mv myfile.txt movedfile.txt
Move to new dirctory:
mv myfile.txt somedirectory/
Change name of directory:
mv somedirectory newnamedirectory
Move and rename one time:
mv somedir/myfile.txt ./somefile.txt
Remove a file:
rm file.txt
Remove empty directory:
rmdir somedir
Remove directory and all inside it:
rm -r somedir
Remove with prompts to confirm removal:
rm -i file.txt
Remove with recursive and force. Be careful with this command!
rm -rf somedir
Read file contents with cat
cat file.txt
Read file contents numbered
cat -n file.txt
Print the beginning of a file:
head # shows the first 10 lines
head -n1 file.txt # -n1 prints the first line
head -c1 file.txt # -c1 prints the first character
print the last content of the file:
tail file.txt# shows last 10 lines
tail -n1 file.txt # -n1 prints the first line
See difference between 2 files:
diff myfile1 myfile2
diff -r ~/Downloads ~/Documents # Directory diff with -r for recursive
Top comments (0)