0% found this document useful (0 votes)
84 views

Command Description (Short) Example Explanation: Infile Names

The document provides explanations and examples for various Linux commands. It describes commands for viewing files and directories (ls, more, head, tail), manipulating files and directories (cp, mv, rm, mkdir), searching files (grep), managing processes (ps, kill), and displaying the current directory (pwd). Examples are provided for viewing, copying, moving, deleting, and searching for files, as well as killing and viewing active processes.

Uploaded by

baabaabaabaa
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Command Description (Short) Example Explanation: Infile Names

The document provides explanations and examples for various Linux commands. It describes commands for viewing files and directories (ls, more, head, tail), manipulating files and directories (cp, mv, rm, mkdir), searching files (grep), managing processes (ps, kill), and displaying the current directory (pwd). Examples are provided for viewing, copying, moving, deleting, and searching for files, as well as killing and viewing active processes.

Uploaded by

baabaabaabaa
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Command

date sort infile

Description (short)
Writes the current date to the screen Sorts the contents of the input file in alphabetical order

Example
date sort names

Explanation
Mon Nov 20 18:25:37 EST 2000 Sorts the contents of names in alphabetical order None

who who am i

Tells you who is logged onto your server who Tells you your user information who am i whoami

None

clear Echo whatever I type cat file1 file3

Clears the window and the line buffer Writes whatever I type to the screen.

clear echo hey you!

None Writes hey you! to the screen This prints the cheese file to the screen first and immediately follows it with the milk file. Prints the first 10 lines of addresses to the screen Prints the first 25 lines of addresses to the screen Prints the last 10 lines of test.txt to the screen Prints the last 32 lines of test.txt to the screen This will list the groceries file to the screen.

file2 Shows the three files in consecutive order as cat cheese one document (can be used to combine files) milk

head

file

Prints the first 10 lines of the file to the screen head addresses Number of lines can be modified head -25 addresses

tail

file

Prints the last 10 lines of the file to the screen tail Number of lines can be modified here, too tail

test.txt -32

test.txt more input This prints to screen whatever is inputuseful more because it only shows one screen at a time. groceries
scroll bar continues to the next screen return moves one line forward

Q quits G goes to the end


1G goes to the beginning Ctrl u moves up screen Ctrl d moves down screen

ls (-option-optional)

Lists all the nonhidden files and directories ls ls bin

ls -l

or

ll

ls -a

Lists all nonhidden files and directories in ls -l long format ll ls -l work ll work Lists all files and directories including ls -a hidden ones ls -a temp Lists all files and directories in reverse ls -r alphabetical order ls -r abc

ls -r

ls -t

Lists all nonhidden files in the order they ls -t were last modified

Lists all nonhidden files and directories in the current directory Lists all nonhidden files and directories in the bin directory Lists all nonhidden files and directories in the current directory in long format Lists all nonhidden files and directories in the work directory in long format Lists all files and directories, including hidden, in the current directory Lists all files and directories in the temp directory. Lists all nonhidden files and directories in the current directory in reverse alphabetical order Lists all nonhidden files and directories in the abc directory in reverse alphabetical order Lists all the nonhidden files in the current directory in the order they were last modified from most recent to last

ls -t work

NOTE: Options can be combined using ls Important Characters |


>

ls -al

Lists all the nonhidden files in the work directory in the order they were last modified from most recent to last Lists all files (including hidden (-a)) in long format (-l) Lists your files in long format one screen at a time Prints your listing to a file named myfiles Appends your filenames to the end of the allfiles file Runs xclock (a clock) allowing you to keep working Writes your home directory to the screen progA program gets its input from a file named input1

>> &
~ <

pipe directs the output of the first command to the input of another. Sends the output of a command to a designated file Appends the output of a command to a designated file Runs command in the background; you can still work in the window Designates the home directory ($HOME) Designates input from somewhere other than terminal UNIX has a set of wildcards that it accepts. Any string of characters Any one character

ls -l | more ls -l > myfiles ls -l >> allfiles xclock & echo ~ progA < input1 ls *.c ls file?

Wildcards * ? [ ]

Match any character in the brackets (a ls v[6-9]file hyphen is used for ranges of characters) Changes your current directory to the directory specified cd bin cd .. cd ../..

Lists any file or directory (nonhidden) ending with c Lists any file/directory with file and 1 character at the end Lists v6file, v7file, v8file, and v9file

cd directory

Changes directory to the bin directory Moves you to the directory that contains the directory you are currently in Ex. Current directory=/home/users/bob/bin execute cd .. New directory= /home/users/bob or executing cd ../.. New directory= /home/users. Moves you to the directory you just came from Both move you to your home directory (the directory you start from initially) Makes a directory named junk in your current directory Makes a directory in your home directory named left Deletes a file named xyz Deletes the files named xyz and abc Deletes everything nonhidden Prompts at each nonhidden file and lets you decide whether or not to delete it Removes the file program without regard to permissions, status, etc. Each of these will remove the bin directory and everything inside of it. Removes the bin directory if it is empty Forces removal without prompts of the c_ya directory and anything

cd cd ~ cd mkdir dirname Creates a directory You can also designate where the directory is to reside. rm file1 file2 file3 Removes (deletes) file(s) mkdir junk mkdir ~/left

rm -i file1 file2

Prompts before deletion of files *******USE -i AT FIRST******* Forces deletion without prompt regardless of permissions Remove a directory along with anything inside of it

rm rm rm rm

xyz xyz abc * -i *

rm -f file1 file2 rm -r directory rm -R directory rmdir directory

rm -f program

rm -r bin rm -R bin Removes a directory like rm -r does if the directory is rmdir bin empty This combination will force the removal of any file and any directory including anything inside of it rm -Rf c_ya

rm -fR name

rm -Rf name rm -Ri directory

Deletes the contents of a directory and the directory if it rm -Ri rusure is empty by prompting the user before each deletion

inside of it Deletes anything in the directory called rusure that you verify at the prompt, and if you remove everything in the directory, you will be prompted whether you want to remove the directory itself or not Deletes the dir1 directory; if bin directory is empty, it is deleted, and if home directory is empty it is also deleted Makes a copy of the file/directory named old and names the copy new, all within the current directory NOTE: If you copy a file to a newfile name and newfile already exists, the newfile contents will be overwritten. Places a copy of file in dir2/ and it retains its original name Copies everything from the dir1 directory located just below where you currently are and places the copy here ( . ) in your current directory Copies execut1 executable file and calls the copy execut2, which also has executable permissions Makes a copy of the directory named old and names the directory copy junk No example or description needed Renames the file (or directory) temp to the name script_1 in the current Directory Moves the script.exe file to the bin directory that is in the home (~) parent directory and it keeps its initial name Moves both script_1 and script.exe to the bin directory May print something like /home/bob

NOTE: Options can be combined using rm rmdir -p directory Removes a directory and any empty parent rmdir -p /home/bin/dir1 directories above it (-pi does the same thing but it prompts before each removal)

cp file1 newname

Copies a file (file1) and names cp old new the copy the new name (newname)

cp file dir2/ cp ../dir1/* .

cp -p name target

Preserves all permissions in the cp -p execut1 execut2 original to the target

cp -R directory target Copies a directory and names the cp -R old/ junk/ copy the new name (target) cp -f name target Forces existing pathnames to be none destroyed before copying the file mv initial final Renames files and directories mv temp script_1

Also moves files to other directories You can do multiple moves.

mv script.exe ~/bin

mv script_1 script.exe ~/bin

pwd

Prints the current directory to the pwd screen Shows certain information about active processes associated with the current terminal Shows information about all processes ps

ps

ps -e

ps -e

ps f

Shows a full listing of information about the processes listed

ps -f

ps -u user_id

Shows all processes that are owned by the person with the pertinent user_id

ps -u bob

Shows a listing of process IDs, terminal identifier, cumulative execution time, and command name Shows a listing of process IDs, terminal identifiers, cumulative execution time, and command names for all processes Shows UID (user or owner of the process), PID (process ID--use this number to kill it), PPID (process ID of the parent source), C (processor utilization for scheduling), STIME (start time of the process), TTY (controlling terminal for the process), TIME (cumulative time the process has run), and COMMAND (the command that started the process) Shows all the processes that belong to the person with the userid bob

ps -ef

Shows all processes in a full listing

ps -ef

Shows all current processes in full listing Kills the process with PID 6969 PID # 6969 doesnt have a chance here. Searches for the string mike in the file named letter and prints any line with mike in it to the screen Searches the file bankletter for the string hayes and prints the number of matches to the screen Searches file1 for hi, Hi, hI, and HI and prints all matches to the screen Searches alpha for abc and prints the matches lines and line numbers to the screen Prints all lines in pencils that do not contain the string lead Prints only lines in meetings that match time exactly Finds all processes in full listing and then prints only the ones that match the string bob to the screen Searches the file b_days for caseinsensitive matches to jan and places the matching lines into a file called mymonth None

kill process_id kill -9 process_id

Stops the process with the said id Destroys the process with the said id

kill 6969 kill -9 6969

grep string file

Searches input file(s) for specified string grep mike letter and prints the line with matches Searches and prints only the number of matches to the screen Searches without regard to letter case grep -c hayes bankletter

grep -c string file

grep -i string file grep -n string file

grep -i hi file1

Prints to the screen preceded by the line grep -n abc alpha number All lines that do not match are printed Only exact matches are printed grep -v lead pencils grep -x time meetings

grep -v string file grep -x string file

grep is useful when you use it in a | pipe ps -ef | grep bob

You can also redirect its output to a grep -i jan b_days>mymonth file.

vi filename

Text editor that exists on every UNIX system in none the world Another text editor Compresses the file to save disk space. Expands a compressed file UNIX programming language none none none none

emacs filename compress filename uncompress filename awk chexp # filename

None None None None Keeps the target computer from deleting all files starting with nr for 1 year (365 days) Makes all files whose name starts with nr never expire or be deleted (infinite) This opens another window like the one you are currently working in. USING XTERM WILL ELIMINATE A LOT OF DESKTOP CLUTTER. I STRONGLY SUGGEST YOU LEARN TO USE IT IN YOUR SCRIPTS.

Keeps the file(s) from expiring (being erased) on chexp 365 nr* the target computer for # days chexp 4095 nr*

xterm xterm -option xterm +option

Opens a new window (x-terminal) for you to work xterm -option sets the option +option resets the option to default

You might also like