basic linux commands

10
Basic Linux commands Almost These Linux commands are basics except those which relate to package manager, we all know that they differs, Ubuntu, Mint ... use Apt, Arch uses Pacman ... Here are some Basic Linux commands : Display Linux distributor's ID lsb_release -is Display Linux release number lsb_release -rs Display Linux code name lsb_release -cs Display machine hardware name uname -m List all PCI devices, such as display card and ethernet card. lspci Reclaim memory which stores pagecache, dentries and inodes echo 3 > /proc/sys/vm/drop_caches Display a list of modules in the Linux Kernel lsmod

Upload: rogerio-pereira-falcone

Post on 11-May-2015

415 views

Category:

Technology


1 download

DESCRIPTION

Linux

TRANSCRIPT

Page 1: Basic linux commands

Basic Linux commandsAlmost These Linux commands are basics except those which relate to package manager, we all know that they differs, Ubuntu, Mint ... use Apt, Arch uses Pacman ...

Here are some Basic Linux commands :

Display Linux distributor's IDlsb_release -is

Display Linux release numberlsb_release -rs

Display Linux code namelsb_release -cs

Display machine hardware nameuname -m

List all PCI devices, such as display card and ethernet card.lspci

Reclaim memory which stores pagecache, dentries and inodesecho 3 > /proc/sys/vm/drop_caches

Display a list of modules in the Linux Kernellsmod

List USB deviceslsusb -v

Display the status of ethernet cardsudo ethtool eth0

Page 2: Basic linux commands

List hardwaresudo lshw

List harddisk partitionssudo fdisk -l

Display SATA harddisk parameterssudo hdparm -I /dev/sda

Display disk space usagedf -h

Display file/folder space usagedu -bsh FOLDER_NAME

Display amount of free and used memoryfree

Display processesps -e

Display a tree of processespstree

Display processes dynamicallytop

Terminate a process with a given process idsudo kill -9 PROCESS_ID

Terminate all processes with a given namesudo killall PROCESS_NAME

List files which are opened by a given processlsof -p PROCESS_IDlsof -c PROCESS_NAME

List processes which opened a given filelsof FILE_NAME

List processes which are using port 80lsof -i :80

Configure an ADSL connectionsudo pppoeconf

Starts up ADSL connectionssudo pon

Shuts down ADSL connectionssudo poff

Page 3: Basic linux commands

Display MAC of a given IP addressarping IP_ADDRESS

Display NetBIOS name of a given IP addressnmblookup -A IP_ADDRESS

Display IP address and MACifconfig -a

Display routenetstat -rn

Set MAC of ethernet interfacesudo ifconfig eth0 hw ether 00:11:22:33:44:55

Display information of a domain namewhois example.com

Display the network path to a given hosttracepath example.com

Request an IP address from DHCP serversudo dhclient

Temporarily restart an init scriptsudo /etc/init.d/SCRIPT_NAME restartTemporarily stop an init scriptsudo /etc/init.d/SCRIPT_NAME stop

Add a usersudo adduser USER_NANEDelete a usersudo deluser USER_NAME

Change user passwordsudo passwd USER_NAME

Changes user fullname, office number, office extension, and home phone number information.sudo chfn USER_NAME

Display user informationfinger USER_NAME

Temporarily prevent a user from logging insudo usermod -L USER_NAME

Revoke the operation abovesudo usermod -U USER_NAME

Add a user to admin groupsudo usermod -G admin -a USER_NAME

Page 4: Basic linux commands

Set the HTTP proxyexport http_proxy=http://PROXY.DOMAIN.NAME:PORT

Modify the information displayed after logging insudo vim /etc/motd.tail

Choose the input method for X Windowim-switch -c

Convert the file name from GBK to UTF8convmv -r -f gbk -t utf8 --notest FILE_NAME

Convert the file content from GBK to UTF8iconv -f gbk -t utf8 FILE_NAME

Convert tags in '*.mp3' from GBK to UTF8find . -name '*.mp3' -execdir mid3iconv -e GBK {} \;

Read a long fileless FILE_NAME

Print lines matching a patterngrep REG_EXP FILE_NAME

Display a list of file name. The files contain a given string.grep -lr REG_EXP PATHNAME

Display all '.txt' filefind . -name '*.txt'

Create two empty filestouch file_name_1 file_name_2

Create directory. Create parent directories as needed.mkdir -p /tmp/a/b/c/d/e

Change working directory to the home foldercd

Change working directory to the previous working directorycd -

Display hidden filesls -a

Copy directory. Preserve links, file mode, ownership, timestamps.cp -a SOURCE_DIRECTORY DEST_DIRECTORY

Determine file typefile FILE_NAME

Output the last 6 lines

Page 5: Basic linux commands

tail -n 6 FILE_NAME

Copy files via SSHscp -rp FILE_NAME USERNAME@HOST:DEST_PATH

Rename '*.rm' files to '*.rmvb' filesrename 's/.rm$/.rmvb/' *

Change the file name to lowercaserename 'tr/A-Z/a-z/' *

Display subdirectories in current directoryls -d */.

Display file number in current directoryls . | wc -w

Extract "*.gz" filegunzip FILE_NAME.gz

Extract "*.tar.gz" filetar zxf FILE_NAME.tar.gz

Extract "*.tar.bz2" filetar jxf FILE_NAME.tar.bz2

Do compressiontar czf FILE_NAME.tar.gz FILE1 FILE2 FILE3tar cjf FILE_NAME.tar.bz2 FILE1 FILE2 FILE3

Displays a calendarcalcal MONTH YEAR

Set the date and time via NTPsudo ntpdate ntp.ubuntu.com

Poweroff your computersudo haltsudo shutdown -h now

Poweroff your computer in 23:00sudo shutdown -h 23:00

Poweroff your computer after 60 minutessudo shutdown -h +60

Reboot your computersudo rebootsudo shutdown -r now

If you want some program to start up automatically, please put '.desktop' files into

Page 6: Basic linux commands

'$HOME/.config/autostart'

You can configure "preferred applications" by this file "$HOME/.local/share/applications/mimeapps.list"

Continuously monitor the memory usagewatch -d free

Display HTTP HEAD responsew3m -dump_head http://example.com

Display file content with line numbernl FILE_NAME

Eliminate Rootkitsudo rkhunter --checkall

Change hostnamesudo hostname new_name

"Tasksel" group software packages into "task"s. You can select a "task" and then install all necessary software packages. It is easy to set up LAMP servers or cloud computing servers.

Show all taskstasksel --list

Display the extended description of a tasktasksel --task-desc lamp-server

List the packages which are parts of a tasktasksel --task-packages lamp-server

Install/remove a taskgksudo tasksel

Change Process priorityrenice NEW_PRIORITY `pgrep NAME_OF_PROCESS`example: renice 5  `pgrep firefox`            renice -5 `pgrep wine-server`                    high <------------------> lowNEW_PRIORITY = -19, -18, -17 [...] 18, 19, 20

Clear Bash historyhistory -c

If you want to use colorful "ls", that is, use colors to distinguish types of files, you can add these lines in $HOME/.bashrc:

if [ "$TERM" != "dumb" ]; then    eval "`dircolors -b`"    alias ls='ls --color=auto'fi

Page 7: Basic linux commands

$HOME/.thumbnails/ directory is a cache dir GNOME makes when you browse through your folders in nautilus.It contains thumbnail pictures of picture files you've previously looked at.

You can get its total size bydu -bs $HOME/.thumbnails/

You can delete the files in the .thumbnails directory that haven't been accessed for seven days, to free disk space.find $HOME/.thumbnails/ -type f -atime +7 -exec rm {} \;

Capture screen after 10 secondsgnome-screenshot -d 10Capture current window after 10 secondsgnome-screenshot -wd 10

Start GConf editor:Press Alt+F2, type 'gconf-editor'.

Set apt sourcesudo software-properties-gtksudo software-properties-kde

Display the packages which are not installed but have remained residual configdpkg -l | awk '/^rc/ {print $2}'

Add a PPA repository:sudo add-apt-repository ppa:PPA-REPOSITORY-NAME

Display a list of files. The files are installed from a given package.dpkg -L PACKAGE_NAME

Display a list of packages. The packages installed a given file.dpkg -S FILE_NAME

Display a list of packages. The name of packages matches given regex pattern.apt-cache search REG_EXPRESSION

Display a list of packages. The packages provide a given file.apt-file search FILE_NAME

Display a list of packages. The given package depends on the list of packages.apt-cache depends PACKAGE_NAME

Display a list of packages. These packages depend on the given package.apt-cache rdepends PACKAGE_NAME

Prompt for a disk to be inserted and then add the disc to the source list.sudo apt-cdrom add

Install the newest versions of all packages currently installed on the system.sudo apt-get upgrade

Page 8: Basic linux commands

Delete residual package configuration files.dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P

Automatically install necessary files for './configure ; make ; make install'sudo auto-apt run ./configure

Save the list of packages currently installed on your system.dpkg --get-selections | grep -v deinstall > SOME_FILEThen use the file to restore packages.dpkg --set-selections < SOME_FILE ; sudo dselect

After running "sudo apt-get install", "*.deb" files are stored in "/var/cache/apt/archives"You can clean this directory by:sudo apt-get clean

Display URL for a given packageapt-get -qq --print-uris install PACKAGE_NAME

Display some statistics about the apt cacheapt-cache stats

Display all package nameapt-cache pkgnames

Display some information of a given packageapt-cache show PACKAGE_NAME