Below are some important commands you need to know to start your journey into Linux.
User-based command
who
— display which user is logged inwhoami
— display the system’s usernameid
—display names and numeric ID’s (UID or group ID) of the current user.groups
— display the groups to which the user is belonging to.adduser username
— Adds a userEnable/Disable user — To disable / lock the password of user account use below command. This will not disallow ssh-access on Ubuntu. This prepends a ! to the password hash so that no password will match it anymore.
sudo passwd -l ‘username’
— Disable a usersudo passwd -u ‘username’
— Enable a user
7.sudo userdel -r ‘username’
— Delete a user
8.sudo usermod -a -G GROUPNAME USERNAME
— Add user a to a usergroup
9.sudo gpasswd — delete USERNAME GROUPNAME
— Remove user from a user group
10.users
— display the username of all users currently logged in
11.lastlog
— display the details of a recent login of all users
12 . Five ways to become a sudo user in Linux OS
- sudo -i
- sudo -s
- sudo su -
- su root
- su -
Directory based commands
pwd
— display present working Directoryls
— to list directories (mkssoftware.com/docs/man1/ls.1.asp)mkdir
— to create a directoryrmdir
— to remove the directorycd
— to change directory to $HOME directorycd /folderpath
— to change the directory to a particular pathcd ..
— change the directory to one level up in the directory tree
File-based commands
touch filename
— to create an empty filerm filename
— remove a filerm -r directory
— delete a directory recursively along with its contentcp file1 file2
— copies the content of file1 into file2cp -r dir1 dir2
— copies the content of dir1 into dir2cat filename
— print the content of the filehead filename
— print the first 10 lines of a filetail filename
— print the last 10 lines of a file
System based commands
uname -a
— display system and kerneldate
— display system dateuptime
— display uptime
Hardware-based commands
cat /proc/cpuinfo
— display information about the CPUfree
— display total memory available and the memory usedlsblk
— list of disks and their partitions
Seach files
find / -name "hosts"
— Find files owned by hosts in / directoryfind / -name "hosts*"
— Find files starting with hosts in / directoryfind / -user username
— Find files owned by usersfind / -size +2G
— Find file whose size is greater than 2GB
File Permissions
###File Permission numbers
4 — read(r), 2 — write(w), 1 — execute(x)
chmod 755 filename
— set read, write and execute permission to owner and read, execute permission to group and everyonechown username filename
— change ownership of the file
Process commands
ps
— to check active running processestop
— display real time processeskill pid
— kill process with pidkillall name
— Kill all processes beginning with the name
Archive and Compression commands
tar -cvf my_archive.tar /home
— create archive file name my_archive of home directorytar -xvf my_archive .tar
— extract my_archive.tar to current directory
Terminal shortcuts
- Tab — autocomplete commands
- Ctrl+C — kills currently executing the command
- Ctrl+L — clear terminal
- Ctrl+D — to get back to the original user
- Ctrl+U — erase everything from the current cursor position to the beginning
- Ctrl+A — Move the cursor to the beginning of the line
- Ctrl+E — move the cursor to the end of the line
Thank you for reading and I hope you found it useful. Follow me for more :)