Unix Commands
-
Upload
scribbertiger -
Category
Documents
-
view
107 -
download
3
Transcript of Unix Commands
![Page 1: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/1.jpg)
TEXT EDITOR PICO$ pico^X (exit) ^ means you hold CTRL^o puts the text OUT to a file and then prompts you to name$ pico filename the filename means that if it exists, you open it and if it doesn't you create itright click of the mouse paste the mouseCTRL SHIFT ^ mark or not mark text where the cursor is located^k cuts text out^u brings back the cut out text to the current cursor position^a beginning of line^b back (left arrow)^e line's end^f forward^n arrow down (next line)^p previous line arrow up^v one page forward^y one page back^<space bar> move to next word^c shows current position^d delete one character^h backspace deletion^g display help file (why is it G I don't know)^i tab^j paragraph justify^l redraw screen^r insert text from a file^u un-deletes or un-justifies
it can undelete a last line, set of lines or a block of text^w
![Page 2: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/2.jpg)
UNIX LinuxCOMMANDS
clear this clears the screen
date displays date and is maintained by the systems administratordate -u Universal GMT time
cal shows system calendarcal 7 1776 shows calendar of the 7 th month of 1776 (July 1776)cal -j julian calendarcal -j 2009 shows Julian calendar for the year 2009cal -s Sunday is listed as the first day of the weekcal-m Monday is listed as the first day of the weekcal-y shows all months of the Current Year
ls file structure~ appData/
current_users5pmDocuments/_emacs*Movies/Pictures/current_usersDesktop/Downloads/Library/Music/year_2009notes
mkdir Make Directory
cd Change Directory
w gives you username, TTY From (the internet connection) Login@ idle time, etc
who shows who is logged inwho -H column headingswho -l list of userswho -u shows session idle times (of users)who -q quick list of users shownwho -b shows when system was last booted
whoami shows current account name of the person that is logged in
who am i displays account session infowho are youwho x x
![Page 3: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/3.jpg)
man man -d prints info for debuggingman -f what is
CTRL+Z exit man
whatis shows brief description of a command (help purposes)
man -f = whatis
cat display files as in the termcap file or shells file under /etc foldercat /etc/shells OR cat /etc/termcapthis is “category”cat -n category command with line numberscat -n /etc/shells OR cat -n /etc/shellsthis shows the file at one timeSPACEBAR will gave you page by pagePg DOWN or z or fENTER line by linePg UP or bq quitcreate a file with cat ==> type cat > filenamesave and exit in cat ==> type d while holding the CTRL button
head displays first few lines of a particular file
tail last few lines of a file are displayedtail -n displays the last n lines of a file
less long file displayed ONE SCREEN AT A TIME up / down scrolling
more same as less but you only scroll downwarddisplays screen (entire) of a particular file allowing scroll down
passwd change password-e expires the password-l locks the account-S account status is displayed
•The new password must differ by AT LEAST 3 characters•2 letters and 1 number is the minimum in the 6 character password•cannot be the same as the username
SHORTCUTSALT BUTTON ALT+D DELETE ALT+L NEXT WORD (La proxima)
CTRL BUTTONCTRL+A beginning (AL principio de la linea)
![Page 4: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/4.jpg)
CTRL+K deletes onwardCTRL+B move backCTRL+D exit editing of text (as in CAT)CTRL+Z exit reading text
Prompt $ % >
the latter symbol (>) is called REDIRECTION symbol> used to create a new file or overwrite an existing one and added to a command that produces output>> used to append an existing file
![Page 5: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/5.jpg)
Chapter 2 File System and File Securitymount mount a file systempwd this displays the current directory pathcd change directory to the home directory
man mount manual description on mountmount -t [device destination]mount lists the file systems that are mounted
umountumount/mnt/cdrom this unmounts the mnt cdrom
mountmount -t iso9660 /dev/cdrom /mnt/cdrom OR mount -t iso9660 /dev/cdrom /media/cdromThis is the change the mount to mnt or media/cdrom
lsls /Music shows details on the folder called Musicls list of files wide-wisels -l ls with a list long-wisels -a all listed including the hidden filesls -al a combo of -a and -l under ls
PS Variable (Bash Shell)TYPE bash to enter the bash shellTYPE echo $PS1PS1='\d \t>' date and type is “printed” on the screen”PS1='\w>' shows working directoryPS1='$PWD>'
![Page 6: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/6.jpg)
Chapter 3Editors
The VI EDITORvi starts the vi editorvi filename create a file under vi editori at the top of the editor after creating the file, creates insert [basically typing any letter brings you into INSERT mode]ESC this button will take you out of INSERT mode. The period after typing ESC button will repeat the text just typed.SO THERE ARE TWO MODES: INSERT MODE AND COMMAND MODE
COMMAND MODE the bottom of the screen doesn't show the modeH in command mode top upper left cursor moveL in command mode last lineG in command mode last linenumberG in command mode AS IN 2G go to second line startw in command mode go forward one wordb in command mode go back one worddd in command mode delete the line (DON'T PRESS ENTER!)
if you type a number it will erase x amount of lines from the cursor downwarddw in command mode deletes the word where the cursor is located atx in command mode deletes the letter cursor is on (DON'T PRESS ENTER!)d$ in command mode deletes from cursor point to end of line (DON'T PRESS ENTER!)d0(zero) in command mode deletes from cursor ponit to the beginning of the line (DON'T PRESS ENTER!)
COMMAND MODE SEARCHtype /type the letters you want to searchhit entertype n to find the nextIn Fedora it will search each occurrence containing what you typed for search
FILES STATUS INFORMATIONCTRL+gCTRL+Gboth will give you file status
: COLON for COMMAND MODEyou type the colon after hitting escape to be out of the INSERT MODE, to type commands on the bottom
: 1,$s/text/documents/g MEANS first line, to the end of the line ($), search for text replace with documents, everywhere it occurs on each line (g)
:w WRITE (save the file):x :wq :ZZ Save and Exit
![Page 7: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/7.jpg)
REMEMBER THAT ^ MEANS YOU NEED TO HOLD DOWN THE CTRL KEY FIRST!:r filename this causes one file (filename) in the same directory to be copied to the current file:! cal brings up cal in the vi editor
CTRL+z Access the command linefg to return from command line back to text editor FOREGROUND
:help Help menu:q INSIDE of the help menu this will take you out and back to vi editor
:set number this sets number to the left hand side line by line
DELETION LINES NUMBEREDto delete lines 7 thru 9 :7,9dcut the first three lines :3ddPASTE :pPRINT :!lpr filename
MORE VI EDITOR COMMANDS!
Keys pressed Text deletedx character under cursor12x 12 charactersX character to left of
cursordw word3dw three wordsd0 to beginning of lined$ to end of linedd current line5dd five linesd{ to beginning of
paragraphd} to end of paragraph:1,. d to beginning of file:.,$ d to end of file:1,$ d whole file
delete text, move to a character and then type “x”You can undo a command (reverse its effects) by typing “u”To search for a text pattern, type a forward slash (/),
![Page 8: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/8.jpg)
type the pattern, and press Enter
Keys pressed
Text changed or replaced
cw word3cw three wordscc current line5cc five linesr current character onlyR current character and those to its rights current characterS current line~ switch between lowercase and uppercaseSearch Finds/and next occurrence of ``and'', for example, ``and'', ``stand'', ``grand''?and previous occurrence of ``and''/^The next line that starts with ``The'', for example, ``The'', ``Then'', ``There''/^The\> next line that starts with the word ``The''/end$ next line that ends with ``end''/[bB]ox next occurrence of ``box'' or ``Box''n repeat the most recent search, in the same directionN repeat the most recent search, in the opposite direction
Command Description:s/pear/peach/g replace all occurrences of ``pear'' with ``peach'' on current line:/orange/s//lemon/g change all occurrences of ``orange'' into
``lemon'' on next linecontaining ``orange''
:.,$^<file/directory/
![Page 9: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/9.jpg)
g replace all words starting (note word anchor ^<) with ``file'' by
``directory'' on every line from current line onward, for
example, ``filename'' becomes ``directoryname''
:g/one/s//1/g replace every occurrence of ``one'' with 1, for example,
``oneself'' becomes ``1self'', ``someone'' becomes ``some1''
EMACS COMMANDSCTRL+x then CTRL+s save the fileCTRL+x then CTRL+c exit the fileCTRL+x then u OR - undo the last change
CTRL+f move forward a character with the cursorCTRL+b move backward a character with the cursorSHIFT<ALT +(plus sign) takes you to the top of the fileSHIFT>ALT +(plus sign) takes you to the end of the file
CTRL+k cut a line outCTRL+spacebar to begin a block of text highlight for copyingALT+w to end a block of text highlight for copyingCTRL+y pasteALT+(plus sign) fill lines with text; place text in one line and continue forward
CTRL+s presents a prompt I-search for the purposes of searching and type what you're looking fortype CTRL+s to find next in the search;
CTRL+r after typing CTRL+s, this is used for moving backward in the search
MORE ON CUTTING AND PASTINGCTRL+SHIFT 2 (@) marks current cursor positionCTRL+k cut outCTRL+y pasteCTRL+w cuts to the current positionREMEMBER THAT ^ MEANS CTRL BUTTON IS HELD^a Move to beginning of line^b Move back one character
(same as left arrow)^e Move to end of line^f Move forward one character
(same as right arrow)^n Move to next line (same as
down arrow)^p Move to previous line (same as
up arrow)^
![Page 10: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/10.jpg)
v Move forward one page
^x ^s Save buffered text to currently specified file^x ^w Write buffered text to a specific file^x ^f Find a file and copy it into buffer^x ^c Exit
"emacs " (if you are in
"scratch" mode it will
NOT
warn you to
save your work)
^d Delete character at current position^s Search forward^r Search backward^k Cut (Kill) text from cursor to end of line^@ Set "Mark"^w Cut text from "Mark" to current cursor position^y Paste text at current cursor position^x u Undo most recent command^- Undo most recent command (alternate)^g Cancel command ("Get out" of a string of ctrl commands)
:lpr -P prints to a specific printer-# prints a specific number of copies-r deletes the print file from disk storage
![Page 11: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/11.jpg)
Chapter 42GddGp:x redirects a file to this command as follows in vi editor: vi file in question < file containing this command, 2GddGp:x
So vi testfile < commands takes the commands like 2GddGp:x and alters testfile
> creates a new file for example > newfile1 will create a new file called newfile1
touch will cause date and time to be modified in its listing of ls -l
rm -i this will prompt you to ensure you want to remove file such and suchif you want to delete or remove said file type y and hit Enter
REMOVING DIRECTORIESTo remove a directory that has a directory inside of it or is not empty use the following command:
rmdir subdirectory/sub-subdirectory
CREATE SUBDIRECTORIESmake sure your parent or main directory or top directory is created or exists and then type the parent directory and / and then then name of the new directory:
mkdir existing directory/subdirectory_now_created
COPY OR MOVE FILES FROM THE DIRECTORY TO THREE DIFFERENT SUBDIRECTORYcp directory/file directory/subdiretory1cp directory/file directory/subdirectory2cp directory/file directory/subdirectory3
mv directory/file directory/subdiretory1mv directory/file directory/subdirectory2mv directory/file directory/subdirectory3
RENAMING A FILEmv old_file name new_file name
FIND A FILEfind -name file1
Again the Commands:cat sends text to an output or creates filestouch creates empty files
-a updates access times only-m modification time only is updated-c prevents touch from creating a file if it doesn’t already exist
rm removes an empty directory or removes a filerm –r this is called RECURSIVE DELETION it causes the contents of the file and the file directory to be removedrm –f forced removalrm –rf kills a foldercp copy
![Page 12: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/12.jpg)
mv movefind
cut removes specific columns and fieldspaste joins text of different files in side by side fashionsort command sorts a file’s contents two ways: either –alphabetically or numerically*sort results can be redirected to output to another fileChmod with x run or execute scriptsjoin command to link files (using a common field)used in relational database processinguse the join command to create reports showing the relationship between two files
awk command to create a professional looking report; it allows you to do the same thing as the cat command
du disk storage of default 512b blockdu –s summarizedu –c grand total sort –n sort by number (n is given a value) value
Examplespast product1 product2this means that the files called product1 and product2 are combined together
ls oops 2> errfilemeans that the listing of “no such file or directory” (assuming the file oops doesn't exist) is passed and kept in a file called errfile
>newfile creates another file called newfile
ls -l newfile3 means that the detailed listing is passed and kept in file called newfile3
rm -i newfile2 prompts you if you want to remove file called newfile2
To create multiple files do this:touch file1 file2 file3 filegood filebad [each of these is a file with different names]
To rename a file do this:mv old_name_file new_name_file
cut -f4-6 -d: corp_phones1this command line means “cut the fields (-f)in positions four through six (4-6)
with the delimiter colon character (-d:)in the file named corp_phones1”
![Page 13: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/13.jpg)
cut -c14-25,26-35,36 corp_phones2this command line means “cut the characters (-c)in positions 14 through 25, 26 through 35 and position 36 (14-25,26-35,36)in the file named corp_phones2”
-t: -k 4 corp_phones1-t: this means the seperator character is : colon-k means specifies sorting4 means specifies sorting on the fourth field
Other examples:sort -t: -k 5 corp_phones1
Fixed-length filesort -k 4 corp_phones sort -k 5 corp_phonesThis each means to sort by the fourth and then fifth fieldsSo if your 4th field is the last name in the records then it sorts by last name
cut -f2 -d: products > p1This means that the field in position 2 separated by delimiter : (colon) in the products file and place it into p1
sort -o vrep -m v3 p3sort or direct output (-o) after you merge data in v3 and p3 into a file called vrep
join -a1 -e "No Products" -1 1 -2 3 -o '1.2 2.2' -t: vendors products > vreport ; cat vreportThis is the join command used to create a report
-a tells the join command to print a line for each UNPAIRABLE LINE in the file number
-e lets you print a message where the unmatched (-a1) record is found; the printed message is followed in quotes
-1 and -2 refer to the first or second specified file such as file1 or file2 or in the above example vendors products
-o where the match does take place these fields will be output
1.2 2.2 this refers to file 1 as in 1.2 and file 2 as in 2.2the above 2s after the period is in reference to 2nd field
-t as with -d this refers to the field separator or delimiter Finally the join command places the output to a new file called vreport
![Page 14: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/14.jpg)
awk -F: '{printf "%-28s\t %s\n",$1,$2}' vreport
awk -F: this calls Awk program up-F: is like -t or -d; it advises the delimiter or field separator
'{printf "%-28s\t %s\n",$1,$2}' represents what is to take place on each linewhat is enclosed in ' ' is the enclosed action
printf is a print formatting function from the C programming language
% what is to be printed28 how many characters you want to displays string\t inserts a tab character into the edit pattern%s specifies that another string field should be printed \n skip a line after printing$1 $2 both mean that the first and second (1, 2) fields in the input file should be placed in the edit pattern where the two s characters appear (the s prior to the \ )
Getline this is an option used in Awk that is designed to read inputafterward it reads the input and places it into a variable such as getline d means
“read the input and place it into variable d”
![Page 15: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/15.jpg)
Alt+D = deletes the selected wordAlt+L = used to move to character just before the next wordCtrl+A = moves the cursor to the beginning of the command lineCtrl+K = deletes the command line from the cursor's current positionCtrl+B = moves one character back
date ; caldate ; who -uH
![Page 16: Unix Commands](https://reader030.fdocuments.in/reader030/viewer/2022020723/5473b0bfb4af9f586b8b457c/html5/thumbnails/16.jpg)
Help pages for CIS students
http://www.cis.fiu.edu/support/unix/unix-tutorial/frames2.html
http://www.cis.fiu.edu/support/docpages.php?file=unixguide.xml
http://www.cis.fiu.edu/support/csnetinfo/index-aul.php