<<

Commands (09/04/2014) • Access control – login – yppassswd – • Login as Super – su • Login as user • Root Prompt – [root@localhost ~] # • User Prompt – [bms@raxama ~] $ On Line Documentation – man • Working with directories – –p ... {-p create all directories in if not present} mkdir –p /2015/Jan/21/14  will create /2015, Jan, 21 & 14 in case any of these is absent –

-r ... Man Pages • 1 Executable programs or commands • 2 System calls (functions provided by the kernel) • 3 calls (functions within program libraries) • 4 Special files (usually found in /dev) • 5 formats and conventions eg /etc/passwd • 6 Games • 7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7) • 8 System administration commands (usually only for root) • 9 Kernel routines [Non standard] – man , {,,,,} – man –k mysql, man –k dhcp – man crontab ,man 5 crontab – man , man 3 printf – man read, man 2 read – man info Runlevels used by Fedora/RHS Refer /etc/inittab

• 0 - halt (Do NOT set initdefault to this) • 1 - Single user mode • 2 - Multiuser, – without NFS (The same as 3, if you do not have networking) • 3 - Full multi user mode /o X • 4 - unused • 5 - X11 • 6 - reboot (Do NOT set init default to this) – init 6 {Reboot System} – init 0 {Halt the System} – reboot {Requires Super User} – • in [2-7] mode – tty switching • • In Fedora 10 tty1 is X. In earlier versions tty7 is X – X Restarting • Command General Info

• Some Common Flags – -r / -R recursive operation -l  long format – -h human readable form -x  extract/extended – -k in Kilo -i  interactive • Meta Characters – * {all 0 or } – ? {Exact one} – > Standard out /File (Overwrite) – < Input from Standard in / File – >> Redirection Standard out /File (Append) – | Pipe – ^ Hat – @ the rate – & ampersand – # – ! Exclamatory Sign – {}Curly Brackets/ Braces – [] Big Bracket/Braces – () Small Brackets/Braces – * Start – ~ Tilde – ? Question Mark/ Sign of Interogation – / Slash – \ Back Slash – ` Back Quote – ‘ Single Quote – “ Double Quote – , Comma – : Semi Colon – : Colon – . / Full Stop – > Greater Than , Redirected to – >> Double Redirection to – < Less Than / Redirection from – $ Dollor – + Plus – - Minus – _ Under score –  Tab • of the command are kept in /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin area. So keep these directories in your PATH | (pipe), more,

–lt | more • ls –lt | less • /etc/passwd | grep | grep -i -e oo -e my -e mm -e su|awk -F: '{print $1","$7}'> /tmp/login • | less Unix commands

listing – ls -altRdgh • -a all • -l long format • -t sorted by order • -R recursive • -d show only directory name • -g show group name also • -h human readable form (Kilo , Mega ,Giga ,T era ,P eta ) – ls –lt /dev/ttyUSB* – ls –al /etc » {to . Files also} – cwd {current } – {present working dirrectory} Redirection • stdin  0, stdout 1 & stderr  2 – ls > ls.out – –f /var/log/messages – cat < /etc/passwd – echo “” > /dev/null – ls *.txt *. *.hhh > out 2>&1 • Put stderr on the same stream as stdout – ls *.txt *.c *.hhh 2> out 1>&2 • Put stdout on the same stream as stderr. Here stderr is redirected to “out” – ls *.txt *.c *.hhh > out 1>&2 • Put stdout on the same stream as stderr is by default terminal not file “out”. “out” file is for stdout which has been redirected to stderr. Output will appear on screen Unix Commands • Examining text files – cat – more • only down traversing allowed – less • both up/down traversing allowed – tail - • shows last n lines of a file – –c –l –w • word counting • -c only character count • -w only word count • -l only line count file • tells about of file for – set • See set variables Unix commands • Text files contd’ – grep -i - –e “str” –e “str2” • to find occurrence of the “str” in file/s, -i flag is used to ignore case. • -v List those files which do not have the “str” • -e grep -i -e lib -e root /etc/passwd diff • to see the difference between file1 & file2 – or diff • for comparing two files f1 & f2 – awk/gawk • cat /etc/passwd | awk –f: ‘{print $1 “:”$5}’ – sed • sed s/root/boot/ new • sed 's/\/usr\/local\/bin/\/common\/bin/' fout – //gvim Unix commands • File management – • for changing permission of file/directory. • d rwx rwx rwx {own group other} • Values between 000 – 777 • 1 – Execute, 2- • 3 - Write+, 4 – Read • 5 – Read+Ex, 6 – Rd+Wr • 7 – Rd+Wr+Ex, 0 – No Perms – -R • to change ownership of file/dir – R • to change groupid of file/dir – -r • will not work across the file systems – rm -r Unix commands • Conversion of files – {Disk } – Create Installable Pen drive for Cent OS 6.5

# dd if=CentOS-6.5-x86_64-bin-DVD1.iso of=/dev/sdb – Create Pidora bootable SD Card for Respberry Pi

# dd bs=4M if=2015-05-05-raspbian-wheezy. of=/dev/sdd

{Octal Dump } # od –cx /etc/hosts • Process related commands – aux {Process Status } • to see all process – • To see the complete process -n • -n Killing Priority Level • to kill a process – • Kill all processes related to • killall wvdial – bg {BackGround } • to put a process in background – fg {ForeGround } • to put a process in foreground Unix commands

• Printing – lpr -P • See Print Queue – lpq -P • Print Job Removal from Queue – lprm -P • to manage printer – lpc • to see the queue status – lpstat Unix commands • General commands – find -print • to find a matching file • find /home -type f -name "*.obj" -exec rm -f {}  find all .obj files in /home & remove • find / -mtime +50 –mtime -100  files modified within last 50 to 100 days – which • tells about the path of the file – • tells about how many person are currently working on the system – who am I • tells about current user – W All logged in users – id • tells about current uid/gid – free • Display amount of free and used memory in the system Unix commands • General command contd’ – finger • tells about login-name – • calendar command – date {hwclock, clock} • set/get date & time – –h • tells about disk free space in human readable form – -s -k –h • tells about disk usage • Preferably use –h in place of –k – • to print out their bootup messages Unix commands • General commands contd’ – • to display on terminal – • For updating last modification time of file/dirs – • to split a file in various pieces – sort -n • sort a text file in various ways • -n Numeric Sort – -s • to create a soft between src & dst Unix commands

• General commands contd’ – newgroup • ( the current group) – -n • deny other uers to write on your terminal – mesg -y • allow other uers to write on your terminal – write • for writing a message on @ Unix commands • General commands contd’ – stty erase • for setting the backspace char – stty –F -a • Show the current setting of – stty –F [-] • Set/reset [use “–”] parameter – stty –F /dev/RF1 –crtscts • unset parameter “ crtscts ” – stty –F /dev/GSM crtscts • set parameter “ crtscts ” – stty –F /dev/GPS –g • print all current settings in a “stty” readable form Unix commands

• System commands

• Writing memory buffers into disk • time • tells about elapsed real, user & system time • is an octal 3 digit number • sets default permission of newly created files (compliment of file- permission) Unix commands

• System commands contd. – -a • gives detail about hostname, OS, OS . – • tells about system’s uptime details, no. of users, load etc – ^d • to send to all user of the system. – halt System halt – poweroff System – reboot System reboot Unix commands • System commands – tar files [] • main flags are • -v verbose • -t show list of files in a tar tape/file • -x extract files • -c copy files in archive media/file • -f make a tar file as • -I include only those files which are listed in • -i ignore checksum errors • -z the archive through gzip • X – excludes files which are listed in – if one file name is mentioned in inlude- file asw ell as in exclude-file then file will not be in tar Disk:System commands • [options] { Check} – -A check all FSs listed in /etc/ – -a automatic repair – -r ask confirmation before update

[options] {Make File System} – -t fs-type {ext4, xfs for }

• mkswap -c /dev/hda2 {Make Swap Area} – -c means check for bad blocks • swapon

• format {Format File System} – interactive command to format disk • – Mount Pen Drive, CD/DVD Drive, NTFS, NFS file system • Mount /dev/sda1 /mnt • umount – Unmount Pen Drive, CD/DVD Drive, NTFS, NFS file system • umount /mnt • exportfs –a -u {/etc/exports} – -a Export or unexport all directories – -u Unexport one or more directories Disk:System commands • fsck An interactive utility for partitions – Internal commands – a make partition active/in active – d delete partition – l list type of partition – m shows list of all commands – n add new partition – q quit without save – t change file-system type – w write partition table & exit – e list extended partitions – r return to main menu • List disk Partitions – -l Unix N/W commands

[] – for connecting remote to work. • [s] ftp – interactive file transfer utility – Some most usable ftp Internal commands • bin – to set transfer mode as binary • prompt on/off – use this option with off if one is using mget or mput and want to copy all files. Unix N/W commands • Ftp contd’ • ls – to see the list of remote directory • dir – to see the list of local directory • cd – change current path to in reomte system • lcd – change current path to in local system • get – to copy from remote ststem to local system • mget – (wildcard characters are valid here) – to copy from remote ststem to local system • put – transfer a local file to remote system Unix N/W commands

– ftp contd’ • mput – (wildcard characters are valid here) – transfer local files to remote system • close – close the current connection • open – open a new ftp session with remote host . • user – to login as user • quit – to close the ftp session and come out of ftp shell. Unix N/W commands

• ping – tells whether hosts is alive ? • hostname – tells the hostname of the system • domainname – tells the domain name of the system • route – To manage routing table – route add –net 172.27.0.0 netmask 255.255.0.0 gw 172.27.16.254 • – Traces the network connectivity route for the given machine • iptables –L – Lists current IP-Table entries • iptables –F – Delete all rules in chain or all chains Unix N/W commands • -a -r -n -i .. – -a tells status of all open sockets and routing table info – -r tells routing table info. • arp -a – to get IP address verses ethernet address mapping of up systems. • – tells about IP address of a given system and hostname if one is providing IP address. • – Next better which replaces nslookup • eth0 – To know ethernet/mac and IP address, gateway, subnet mask Secure N/W Commands • ssh {Secure Shell} – ssh user@host – Replaces old “telnet” • sftp {Secure ftp} – sftp user@host – Replaces old “ftp” • scp {Secure cp} – scp –r login@host/ – Replaces old “rcp” Disk:System commands

• lilo – to update LILO Boot Info (obsolete)

• grub – To manage boot/multi boot info – Configuration file /etc/grub.conf Unix N/W commands Obsolete N/W commands • rcp -r remhost:path – remote file/directory copy from “remhost”. Similar to ftp • rsh – remote execution on . Result will appear on local system’s terminal. • rlogin – similar to telnet • rwho – similar to telnet for above commands file is required. Security hole Unix N/W commands

Obsolete N/W commands contd • user@host – one can interactively talk with user at host • ruptime – tells uptime details about udev commands

• /sbin/udevadm info -n /dev/ttyUSB1 -a System Service Management Old Commands • chkconfig on/off • service start/stop/restart/reload/status New Commands • systemctl enable/disable/start/stop/restart/reload/status Network old & new commands • ifconfig [] [up/down]  ip addr [show] [up/down] • route  ip route • netstat –rn  ip route • arp –a/ -n  ip neigh • nslookup [ip /host]  dig [ip/host] rpm & yum

• rpm –qa | grep • # rpm -qf /etc/passwd setup-2.8.14-20.el6_4.1.noarch {tells that /etc/passwd file is due to setup-2.8.14-20.el6_4.1.noarch rpm} • yum search • yum -y – -y is automatic “” • yum remove

• yum update –y  updates to latest version

• yum upgrade –y  upgrade to new version of Linux • yum localinstall RAID, Physical Volume, Logical Volume & Filesystem • mdadm –detail • cat /proc/mdstat {shows details of given RAID device} Ex: mdadm --detail /dev/md0 • mdadm – create –verbose /dev/md0 – level=1/3/5/6 /dev/sda1 /dev/sda2 … {Create a RAID 1/3/5/6 named /dev/md0 using hard disks /dev/sda1 /dev/sda2 …} • mdadm --fail • mdadm --stop • mdadm --remove /dev/md0 /dev/sdb1 {remove a hard disk /dev/sdb1 to existing RAID array /dev/md0. first execute mdadm –fail/--stop option then remove} Physical Volume, Volume Group & Logical Volume (pv*/vg*/lv*)

• Create Physical Volume # pvcreate /dev/sdb1 /dev/sdb2 • Display physical volume properties – # pvdisplay • Volume group creation – vgcreate vg1 /dev/sdb1 /dev/sdb2 • Display Volume Properties – vgdisplay • create a logical volume – lvcreate -L 200M vg1 -n lv1 • Display Volume Properties – lvdisplay • Format logical volume – mkfs. xfs /dev/vg1/lv1 – mkfs –t ext4 /dev/vg1/lv2 • File system mouting – mount /dev/vg1/lv1 /mnt/ Disk Partition/Resize

• Update the kernel to save the changes without restarting the system. # partprobe • Extend Volume group – vgextend vg1 /dev/sdb3 • Extend Logical group – lvresize -L +100M /dev/vg1/lv1 • Resize the File system of logical volume – resize2fs /dev/vg1/lv1 • Remove Logical Volume – lvremove /dev/vg1/lv1 {first unmout it} • Remove Volume Group – vgremove /dev/vg1 • Remove Physical Volume – pvremove /dev/sdb1 /dev/sdb2 /dev/sdb3 • Resize file system – resize2fs /dev/vg1/fs1 defaults to the size of the device • parted – parted is a and partition resizing program. URLs

• www.cse.iitk.ac.in/users/bms • http://www.tldp.org/LDP/abs/html/ • http://www.grymoire.com/Unix/Awk.html • http://www.grymoire.com/Unix/Sed.html • http://www.tecmint.com/35-practical- examples-of-linux-find-command/ • http://openvswitch.org/support/config- cookbooks/ • http://www.linux- kvm.org/page/Networking • http://www.ciscopress.com/articles/article. asp?p=357103&seqNum=4 • https://documentation.meraki.com/MS/Lay er_3_Switching/Layer_3_versus_Layer_2_ Switch_for_VLANs • http://www.thegeekstuff.com/2011/06/ipta bles-rules-examples/ • http://linuxcommand.org/learning_the_shel l.php