Unix Commands (09/04/2014) • Access control – login <login_name> – exit – passwd <login_name> – yppassswd <loginname> – su – • Login as Super user – su <login> • Login as user <login> • Root Prompt – [root@localhost ~] # • User Prompt – [bms@raxama ~] $ On Line Documentation – man <command/topic> – info <command/topic> • Working with directories – mkdir –p <subdir> ... {-p create all directories in path if not present} mkdir –p /2015/Jan/21/14 will create /2015, Jan, 21 & 14 in case any of these is absent – cd <dir> – rm -r <subdir> ... Man Pages • 1 Executable programs or shell commands • 2 System calls (functions provided by the kernel) • 3 Library calls (functions within program libraries) • 4 Special files (usually found in /dev) • 5 File 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 grep, {awk,sed,find,cut,sort} – man –k mysql, man –k dhcp – man crontab ,man 5 crontab – man printf, 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 w/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} – <ctrl> <alt> <del> • in tty[2-7] mode – tty switching • <ctrl> <alt> <F1-7> • In Fedora 10 tty1 is X. In earlier versions tty7 is X – X Restarting • <ctrl> <alt> <back space> Command General Info • Some Common Flags – -r / -R recursive operation -l long format – -h human readable form -x extract/extended – -k in Kilo Bytes -i interactive • Meta Characters – * {all 0 or more} – ? {Exact one} – > Redirection Standard out /File (Overwrite) – < Input from Standard in / File – >> Redirection Standard out /File (Append) – | Pipe – ^ Hat – @ at the rate – & ampersand – # hash – ! 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 – . Dot / Full Stop – > Greater Than , Redirected to – >> Double Redirection to – < Less Than / Redirection from – $ Dollor – + Plus – - Minus – _ Under score – Tab • Most 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, less • ls –lt | more • ls –lt | less • cat /etc/passwd | grep bash | grep -i -e oo -e my -e mm -e su|awk -F: '{print $1","$7}'> /tmp/login • diff <f1> <f2> | less Unix commands • Directory listing – ls -altRdgh • -a all • -l long format • -t sorted by time 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 working directory} – pwd {present working dirrectory} Redirection • stdin 0, stdout 1 & stderr 2 – ls > ls.out – tail –f /var/log/messages – cat < /etc/passwd – echo “” > /dev/null – ls *.txt *.c *.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 which 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 <file/s> – more <file/s> • only down traversing allowed – less <file/s> • both up/down traversing allowed – tail -<n> <filename> • shows last n lines of a file – wc –c –l –w <file/s> • word counting • -c only character count • -w only word count • -l only line count file <file/s> • tells about type of file for <file/s> – set • See set variables Unix commands • Text files contd’ – grep -i -v –e “str” –e “str2” <file/s> • 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 <search str> grep -i -e lib -e root /etc/passwd diff <file1> <file2> • to see the difference between file1 & file2 – cmp <f1> <f2> or diff <f1> <f2> • for comparing two files f1 & f2 – awk/gawk • cat /etc/passwd | awk –f: ‘{print $1 “:”$5}’ – sed • sed s/root/boot/ </etc/passwd >new • sed 's/\/usr\/local\/bin/\/common\/bin/' <fin >fout – vi/vim/gvim Unix commands • File management – chmod <ooo> <file/s> • for changing permission of file/directory. • d rwx rwx rwx {own group other} • Values between 000 – 777 • 1 – Execute, 2- Write • 3 - Write+Ex, 4 – Read • 5 – Read+Ex, 6 – Rd+Wr • 7 – Rd+Wr+Ex, 0 – No Perms – chown -R <uid> <file/dir> • to change ownership of file/dir – chgrp R <groupid> <file/dir> • to change groupid of file/dir – cp -r <src> <dst> – mv <src> <dst> • will not work across the file systems – rm -r <file/dir> Unix commands • Conversion of files – dd {Disk Dump } – 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.img of=/dev/sdd – od {Octal Dump } # od –cx /etc/hosts • Process related commands – ps aux {Process Status } • to see all process – pstree • To see the complete process tree – kill -n <process-id> • -n Killing Priority Level • to kill a process – killall <ProcessName> • Kill all processes related to <Process Name> • killall wvdial – bg {BackGround } • to put a process in background – fg {ForeGround } • to put a process in foreground Unix commands • Printing – lpr -P<printer> <file/s> • See Print Queue – lpq -P<printer> • Print Job Removal from Queue – lprm -P<printer> <print-job-no.> • to manage printer – lpc • to see the queue status – lpstat Unix commands • General commands – find -print <pathname> <file/s> • 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 <file> • tells about the path of the file – who • 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 <login-name> • tells about login-name – cal • calendar command – date {hwclock, clock} • set/get date & time – df –h • tells about disk free space in human readable form – du -s -k –h <file/dir> • tells about disk usage • Preferably use –h in place of –k – dmesg • to print out their bootup messages Unix commands • General commands contd’ – echo <str> • to display <str> on terminal – touch <file/dir/s> • For updating last modification time of file/dirs – split <switches> <file> • to split a file in various pieces – sort -n <text-file/s> • sort a text file in various ways • -n Numeric Sort – ln -s <dst> <src> • to create a soft link between src & dst Unix commands • General commands contd’ – newgroup <group> • (make <group> the current group) – mesg -n • deny other uers to write on your terminal – mesg -y • allow other uers to write on your terminal – write <user> <terminal> • for writing a message on <user>@<terminal> Unix commands • General commands contd’ – stty erase <BS> • for setting the backspace char – stty –F <device> -a • Show the current setting of <device> – stty –F <device> [-]<parameter> • 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 • sync • Writing memory buffers into disk • time <command> • tells about elapsed real, user & system time • umask <xyx> • <xyz> is an octal 3 digit number • sets default permission of newly created files (compliment of file- permission) Unix commands • System commands contd. – uname -a • gives detail about hostname, OS, OS ver. – uptime • tells about system’s uptime details, no. of users, load etc – wall <mesg> ^d • to send <mesg> to all user of the system. – halt System halt – poweroff System shutdown – reboot System reboot Unix commands • System commands – tar <flags> files [<filename.tar>] • 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 <file.tar> make a tar file as <file.tar> • -I <include-file> include only those files which are listed in <include-file> • -i ignore checksum errors • -z filter the archive through gzip • X <exclude-file> – excludes files which are listed in <exclude-file> – 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 • fsck [options] <filesys> {File System Check} – -A check all FSs listed in /etc/fstab – -a automatic repair – -r ask confirmation before update • mkfs [options] <filesys> {Make File System} – -t fs-type {ext4, xfs for Linux} • mkswap -c /dev/hda2 {Make Swap Area} – -c means check for bad blocks • swapon <filesys> • format {Format File System} – interactive command to format disk • mount <src> <dst> – Mount Pen Drive, CD/DVD Drive, NTFS, NFS file system • Mount /dev/sda1 /mnt • umount <fileSystem> – 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 – fdisk -l Unix N/W commands • telnet [<portno>] <host> – for connecting remote host to work.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages38 Page
-
File Size-