Skip to content

Instantly share code, notes, and snippets.

@greatsharma
Created November 16, 2019 16:30
Show Gist options
  • Save greatsharma/69835357df0a9c0797ad4a051243bb67 to your computer and use it in GitHub Desktop.
Save greatsharma/69835357df0a9c0797ad4a051243bb67 to your computer and use it in GitHub Desktop.
important terminal commands.
* man command [manual for a command]
* sudo -s passwd [to set root password]
* figlet "text here" [show text in design]
* grep pattern file_name [find pattern in file]
* | [pipe commands, eg: cat file | grep pattern]
* > [symbol used for output(stdout) redirection, overwrites]
* ls -al > listing [send all file details in current directory in the file listing]
* >> will append
* < [symbol for input(stdin) redirection]
* sort filename [sort alphabetically]
* -r reverse sorting
* -n sorts numerically
* -f case insensitive sorting
* sudo adduser user_name [add new user]
* getent passwd [list all users]
* finger user_name [info about user]
* sudo deluser username
* sudo deluser --remove-home username [to delete his home directory/
mails as well]
* sudo deluser --remove-all-files username [removes all files as well]
* sudo adduser user_name group_name [add user to a group]
* sudo usermod -a -G group_name user_name [add user to group]
* sudo deluser username group_name
* cat /etc/group [list all groups]
* groups [find groups you are member of]
* newgrp group_name [to be member of group_name, a file cannot be shared by 2 groups]
* hostname
* env [displays all environment variables]
* echo $env_var [prints env_var value]
* NEW_ENV_VARIABLE=value [creates new env var]
* unset var_name [delete env var]
* to run process in background i.e., free terminal for used
* run process from terminal
* press ctr+z
* run bg
* run fg to bring the process back to foreground
* top [all running processes]
* ps u [process status of all process]
* pidof process_name [gives pid of process]
* ps pid [status of pid process]
* kill pid [terminates process]
* nice -n nice_value process_name [launch process with priority, nice_value=[-20, 19], lower niceness hig- her the priority]
* sudo renice nice_value -p pid [renice already running process]
* df -h [all file system with used and available disk space]
* free -m [memory usage in migs, -g for gigs]
* su - user_name [login to user]
* pwd [current directory]
* ls -a [to show all files including hidden]
* ls -larth [to show all files including hidden with detailed descr.]
* ls -l /path/to/file-or-dir [to show permissions on a file/dir]
* chmod ops file/dir [change file/dir mode]
* -rwxrwxrwx user-group-other
* u: user/owner, g: group, o: other, a: all
* + : add permissions to file/dir, - : remove permissions, = : override/set permissions
* chmod u-r file_name [removing read permission for user]
* chmod g+x file_name [adding execute permission to usergroup]
* chmod o=rwx [setting permissions for the 'other' users]
* chown user file/dir [For changing the ownership/user of a file/directory]
* chown user:group file/dir [For changing the user as well as group of a file/directory]
* chgrp group_name file_name [change group-owner only]
* free -m [memory details]
* nproc [# cpu cores]
* ip addr show
* sudo netstat -nltp
* ssh remote_username@remote_host_ip [connect to remote host via ssh]
* ssh-keygen -t rsa [generate ssh key in your system]
* ssh-copy-id remote_username@remote_host_ip [copy the public key to the remote server]
* scp <source> <destination> [copy file]
* To copy a file from B to A while logged into B:
scp /path/to/file username@a:/path/to/destination
* To copy a file from B to A while logged into A:
scp username@b:/path/to/file /path/to/destination
* cheese [open webcam]
* cat file_name [open file in terminal]
* cat > file_name [overwrite content in file in terminal, it first creates if not exists]
* cat >> file_name [append content in file in terminal, it first creates if not exists]
* cat file1 file2 > file3 [concat file1 and file2 and send them to file3]
* echo hello word > file_name [create and write to file]
* mv old_name new_name [change folder/file name]
* rm file_name [delete file]
* nautilus dir [open the directory in file explorer]
* curl [used to transfer data to/from a server]
* pstree -p pid [process tree]
* sudo apt install pkg_name [install pkg]
* sudo apt-get install pkg_name [install pkg]
* sudo apt-get remove pkg_name [uninstall pkg]
* sudo apt-get update [updates only the list of available pkg and their versions]
* sudo apt-get upgrade [upgrades the pkgs to their new versions]
* sudo dpkg -i package_name [install a pkg]
* dpkg -l | grep lxd [check whether a pkg is installed or not]
* which filename [used to locate the exec. file associated with the given
command by searching it in the path env. var.]
* lsb_release -dirc [OS info]
* grep [options] pattern [files] [the grep filter searches a file for a particular pattern of cha racters, and displays available lines that contain that pattern. The pattern that is searched in the file is referred to as the
regular expression (grep stands for globally search for regular expression and print out)]
* sudo systemctl status service_name [check for service is running]
* sudo systemctl enable service_name [enable the service]
* sudo systemctl start service_name [start the enabled service]
* groups [groups you are a member in]
* uname -r [which linux kernel]
* bash shellscript.sh [run shellscript]
* PS1='text : ' [start terminal line with this]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment