Linux commands at the command line

Do these commands in a terminal window. Applications->Accessories->Terminal

The "command line" is in a terminal window. People who have shorter memories have more need to refer to help files like this document. There are so many commands because Unix is so old (1969), handles distributed processing, and is specially suited for programmers. The alternative to the command-line interface is GUI. An introduction to a command that is new to you can often be found on Internet. Most commands are pretty useless to Linux newbies unless there are examples.

Hint: whenever you are working between different directories, you can see both at once by opening two terminals and sizing the windows so they don't overlap. This technique also works if you care to switch between multiple workspaces on your GUI screen.

Where you see sudo, it is often needed by Ubuntu. In Fedora, su - to be the root user.

Contents

ls list files and directories

chmod change permissions

mkdir make a directory

mount mount a file system. If it is mounted by the fstab file during boot, you don't have to

worry about this. USB and other removable devices usually auto-mount.

cd change directory, up or down the hierarchy

/ root

| pipe the output between utilities

gedit graphical text editor; this and other programs can be started from the command line.

cp copy file, directory, dir & subdirectories

ping, traceroute

>, >> redirect, usually to a file

man, info manual

ps processes

dmesg bootup messages

q quit, like quit a manual page

top most active processes

du disk usage

df file system disk space usage

uname system info, like kernel version

tasksel select packages to download. The computer must be connected to Internet.

ifconfig interface (network) config

nmap network map, most sysadmins do not want you to nmap their network, so nmap is used

mainly within your private network space like 192.168.1.x

initctl init daemon control

service run a System V init script

status of a service

cat x put out to the screen the file x. Named after concatenate because it can handle a sequence of files.

apt-get downloading and installing packages, where packages is software applications. Be connected to Internet.

vnstat network traffic monitor

blkid file systems on your system

file type of file or directory

If ls -l shows a file or directory without the write permissions you need,

chmod a+w filename_or_directory p. 411 Dulaney Linux All-in-One for Dummies

then ls -l to check.

sudo mkdir dirname from the directory you want to create it in, then chmod as above

First time to mount a partition of an added hard drive:

sudo mkdir new_dirname from within a directory like /home

chmod a+w new_dirname

mount /dev/sdb1 new_dirname to mount 1st partition of second HDD into the

new_dirname that was just made, new_dirname doesn't

need much free space. Repeat the mount each

power-on or edit fstab, the file system table.

cd / change directory to root cd change to home dir of logged-in user

cd /etc/perl change to a directory two levels down from root

cd .. go up one level pwd present working directory

For reference, most of the directories in root: bin (binary program files) etc lib (library) opt selinux (secure Linux) tmp boot home lost+found

proc (processes, one folder per process) srv (services) usr (user) media root sys var (various) dev (devices) mnt (mount, includes hard drive partitions starting with sda1) sbin

ls list files & directories ls -R see subdirectories ls -l long list showing permissions

ls | less to page forward with spacebar or backward with b, quit with q

ls /etc to see /etc while you stay in another directory

ls -R > /home/OUTPUTofLIST.txt ls -Rl

ls -R /dev | grep dvd to find dvd within /dev directory and subdirectories

ls *.txt ls *.{gif,png,jpg} ls {img,mov}*.*

ls --ignore=[ltuv]* --ignore=ram* in /dev, to ignore loop, tty, usb, vcs, ram

sudo gedit filename to edit a permissioned file, if text editor gedit is installed

cp source_filename destination_dirname copy, include directories as prefix to

filename unless you are in it

cp source_filename destination_filename to change the filename

cp * destination_dirname copy all files from present working

dir to another directory

cp * dest_dir as in cp [cdGNR]* subDIR to copy from present working directory, all files starting with

c, d, G, N, or R to the subdirectory subDIR, which includes all the dir structure down from root

cp -ar source_dir dest_dir to copy even directory structure, p. 130 Dulaney Linux All-in-One for Dummies

ping -c 2 192.168.1.1 ping -c 2 www.hotels.com ping with count=2

traceroute 208.80.154.225 traceroute www.hotels.com

any_Linux_command > new_filename to write lengthy output to a file that you can pick through at your leisure with a text editor like Gedit

man command info command command --help manual, info, short help quit man with q

ps -ef f --headers --sort args > new_filename processes

ps -ef | grep character_string_like_samba if you are looking for

something specific

dmesg -s 100000 > new_filename boot messages

top q to quit play a movie to see big CPU%

sudo du -h all files with path & size from within a directory or even from /

p. 111 Dulaney, for Dummies

df -hT | sort same as GUI system->administration->system monitor->file systems

uname -a > system.txt system info on one line including kernel version, redirected to a file

lspci -vv PCI bus info, verbosely

sudo tasksel alternative to Ubuntu's Software Center

ifconfig in Microsoft Windows, this is ipconfig

sudo nmap -sS 192.168.1.0-254 port scanner for hosts 0 to 254

sudo apt-get install iftop

sudo iftop eth0 or eth1 if you have two NICs top network traffic

sudo nmap -O -sS 192.168.1.0-254 > /home/scinstr/nmap_output SYNs -FO shows operating system

sudo nmap -O -sU 192.168.1.0-254 > /home/scinstr/nmap_output UDPs

sudo nmap -sO 192.168.1.0-254

sudo nmap -sV 192.168.1.0-254 shows workgroups & services like Samba smbd

sudo nmap -sV -vv 192.168.1.0-254 --top-ports 20 -v is verbose and -vv is more so

nmap –iflist for host you run nmap from nmap -sP 192.168.1.0-25 for fast ping scan

sudo initctl list to see services including server services such as samba

service --status-all

from sudo initctl list choose a service and do

sudo service your_choice_of-service start (or stop)

such as sudo service smbd stop to stop the samba daemon

status smbd smbd or any other service

cat filename show the contents of the text file

cat /proc/cpuinfo show CPU info

df -H Filesystem Size Used.........Mounted_on /dev/sdb6 57G 189M 54G 1% /home/data4 sudo apt-get install iftop then sudo iftop ethx where x is 0,1sudo apt-get install vnstat then vnstat -u -i eth0 vnstat -u -i eth1

after an hour or a day, vnstat -h vnstat -tsudo blkid shows file systems and UUIDs especially good when you have partitionsif you see “permission denied,” it may help to precede the command with sudomount shows partitions that are mounted cat /etc/fstabfile filename file directory_name shows what type of file it is file *