Created
October 17, 2014 03:36
-
-
Save deepaknverma/91a6bacede46518f2501 to your computer and use it in GitHub Desktop.
Ubuntu essential commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Doesn't matter how good programmer, system administrator or technologist you are. You always have to refer to online documentation or I say ask GOOGLE to recall | |
those commands. It pisses me a lot. I created this GIST to refer too, whenever I am stuck. | |
---------------------------------------------------------------------------------------------- | |
Privileges Management | |
---------------------------------------------------------------------------------------------- | |
$sudo :– run command as root | |
$sudo -s :– open a root shell | |
$sudo -i :-similar to sudo su - , gives you roots environment configuration | |
$sudo -s -u user name : – open a shell as user | |
$sudo -k :–forget sudo passwords | |
$gksudo command :– visual sudo dialog (GNOME) | |
$kdesudo command :– visual sudo dialog (KDE) | |
$sudo visudo :– edit /etc/sudoers | |
$gksudo nautilus :– root file manager (GNOME) | |
$kdesudo konqueror :– root file manager (KDE) | |
$passwd :– change your password | |
Note:- By default sudo remembers your password for 15 minutes. If you want to change that you can do so by | |
deepak@ubuntu:~$ sudo vim /etc/sudoers :-Add ,timestamp_timeout=X next to env_reset. After editing your file may look like this | |
.................................................... | |
# See the man page for details on how to write a sudoers file. | |
# | |
Defaults env_reset,timestamp_timeout=60 | |
# Host alias specification | |
....................................................................................................................................... | |
X indicate time in minutes. 0 means you need to type evey time when you use sudo. negative value meanes you need to type password again. | |
---------------------------------------------------------------------------------------------- | |
Networking Management | |
---------------------------------------------------------------------------------------------- | |
$ifconfig :– show network information | |
$iwconfig :-–show wireless information | |
$sudo iwlist scan :– scan for wireless networks | |
$sudo /etc/init.d/networking restart :– reset network for manual configurations | |
$ifup :– bring interface online | |
$ifdown :– disable interface | |
$ping :- convert names to IP addresses and vice versa | |
$host name convert names to IP addresses and vice versa | |
$nslookup :-nslookup is a program to query Internet domain name servers | |
$dhclient eth0 :- active interface 'eth0' in dhcp mode | |
$ethtool eth0 :- show network statistics of eth0 | |
$hostname :- show hostname of system [man] | |
$ifconfig eth0 192.168.1.1 netmask 255.255.255.0 :- configure IP Address | |
$ifconfig eth0 promisc :- configure 'eth0' in promiscuous mode to gather packets (sniffing) | |
$ip link show :- show link status of all network interfaces | |
$iwlist scan :- wifi scanning to display the wireless connections available | |
$netstat -tup :- show all active network connections and their PID | |
$netstat -tupl :- show all network services listening on the system and their PID | |
$netstat -rn :- show routing table alike "route -n" | |
$route -n :- show routing table | |
$route add -net 0/0 gw IP_Gateway :- configure default gateway | |
$route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 :- configure static route to reach network '192.168.0.0/16' | |
$route del 0/0 gw IP_gateway :- remove static route | |
$tcpdump tcp port 80 :- show all HTTP traffic | |
---------------------------------------------------------------------------------------------- | |
Dispaly Management | |
---------------------------------------------------------------------------------------------- | |
$sudo /etc/init.d/gdm restart :– restart X and return to login (GNOME) | |
$sudo /etc/init.d/kdm restart :– restart X and return to login (KDE) | |
$cat /etc/X11/xorg.conf :– display configuration | |
$sudo dexconf :– reset xorg.conf configuration | |
Ctrl+Alt+Bksp :– restart X display if frozen | |
Ctrl+Alt+FN :– switch to tty N | |
Ctrl+Alt+F7 :-– switch back to X display | |
---------------------------------------------------------------------------------------------- | |
Services Management | |
---------------------------------------------------------------------------------------------- | |
Essentials services ( networking, mysql, apache2, vsftpd, ssh, nginx ) | |
$sudo /etc/init.d/servicename start :– start service | |
$sudo /etc/init.d/servicename stop :– stop service | |
$sudo /etc/init.d/servicename status :– check service | |
$sudo /etc/init.d/servicename restart :-– restart service | |
$sudo sysv-rc-conf servicename on :-Enabling a service at boot | |
$sudo sysv-rc-conf servicename off :- Disabling a service at boot | |
$sudo update-rc.d servicename defaults :- Enabling a service at boot | |
$sudo update-rc.d servicename purge :- Disabling a service at boot | |
$runlevel :– get current runlevel | |
---------------------------------------------------------------------------------------------- | |
Package Management | |
---------------------------------------------------------------------------------------------- | |
$sudo apt-get update :– refresh available updates | |
$sudo apt-get upgrade :– upgrade all packages | |
$sudo apt-get dist-upgrade :– upgrade with package replacements; upgrade Ubuntu version | |
$sudo apt-get install packagename :– install pkg | |
$sudo apt-get remove packagename --purge :- Remove packgege with configfiles | |
$sudo apt-get autoremove :– remove obsolete packages | |
$sudo apt-get -f install :– try to fix broken packages/unresolved dependencies | |
$sudo apt-get clean :-apt-get clean removes everything except lock files from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/ | |
$sudo apt-get autoclean :-apt-get autoclean removes only package files that can no longer be downloaded. | |
$sudo apt-cache search packagename :- search a packages | |
$sudo apt-cache show packagename :- get information about a packges | |
$sudo apt-cache depends packagename :- get package dependency | |
$sudo apt-file list packagename :- get file names in a package | |
$sudo apt-file search filename :- discovers the package file belong to | |
$sudo apt-file updatelong :- apt-file keeps a database of which files all packages contain, just like auto-apt does and it needs to be up-to-date. This is done by running | |
$sudo apt-get source packagename :-download a source of package | |
$sudo dpkg --configure -a – try :-to fix broken packages | |
$sudo dpkg -l :-get installed package list | |
$sudo dpkg -l packagename :- Query version of package and if package is installed. | |
$sudo dpkg -L packagename :- List all files on the system associated with the package. | |
$sudo dpkg -S filename :- List the package name to which this file is associated. | |
$sudo dpkg -p filename :- Print package information. See /var/lib/dpkg/available | |
$sudo dpkg -i packagename.deb :- Install package. | |
$sudo dpkg -r packagename :- Remove package. Keep configuration files. | |
$sudo dpkg -P packagename Remove package. Remove configuration files. | |
---------------------------------------------------------------------------------------------- | |
File Management | |
---------------------------------------------------------------------------------------------- | |
$vim filename :-Vi fullscreen editor | |
$wc filename :-Line, word, & char count | |
$cat filename :- List contents of file | |
$more filename :-List file contents by screen | |
$cat file1 file2 > file3 :-Concatenates file1 & file2 into file3 | |
$chmod mode file :-Change protection mode of f | |
$cmp file1 file2 :-Compare two files | |
$cp file1 file2 :-Copy file file1 into file2 | |
$sort file :- Alphabetically sort file | |
$split [-n] file :-Split file into n-line pieces | |
$mv file1 file2 :- Rename file file1 as file2 | |
$rm file1 :-Delete (remove) file file1 | |
$grep ‘ptn’ file :-Outputs lines that match ptn | |
$diff file1 file2 :-Lists file differences | |
$head file :-Output beginning of file | |
$tail file :-Output end of file | |
---------------------------------------------------------------------------------------------- | |
Environment Management | |
---------------------------------------------------------------------------------------------- | |
$cd dir1 :- Change to directory dir1 | |
$mkdir dir1 :- Create new directory dir1 | |
$rmdir dir1 :- Remove directory dir1 | |
$mv file1 [file2...] dir :- Move file f to directory dir | |
$mv dir1 dir2 :- Rename directory dir1 as dir2 | |
$passwd :- Change password | |
$alias name1 name2 :- Create command alias | |
$unalias name1 :- Remove command alias name1 | |
$logout :- End terminal session | |
$setenv name var :- Set env var to value var | |
$unsetenv name1 name2...] :- remove environment variable | |
$ls [d] [file] :- List files in directory | |
$ls -1 [file] :- List files in detail | |
$alias [name] :- Display command aliases | |
$printenv [name] :- Print environment values | |
$quota :- Display disk quota | |
$date :-Print date & time | |
$who :- List logged in users | |
$whoami :- Display current user | |
$finger [username] :- Output user information | |
$chfn :- Change finger information | |
$pwd :- Print working directory | |
$history :- Display recent commands | |
$! n :- Submit recent command n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment