|Command structure||command [option]... [argument]...|
/, or a user's home directory.
.and the parent directory with
Many Unix command have options that modify their behavior.
To learn more about a specific command try:
man– show manual for command
info– show info page for command
Consider them travel guides.
info can answer many of your questions.
% pwd /tmp % ls my_file1 % cat my_file1 Hi, everybody! Hi, Dr. Nick!
The simplest way to view the contents of a file is to use:
more– show a file one screenful at a time
cat– dump the complete file to the screen
% ls my_file1 % cp my_file1 my_file2 % ls my_file1 my_file2 % mv my_file1 file1 % ls file1 my_file2 % rm file1 % ls my_file2
Here are three commands for handling files:
cp– copy a file to some location
mv– move a file to a new location
rm– remove a file
% ls my_file2 % mkdir new_dir % ls -l total 8 -rw------- 1 boese fac 4 Jan 19 14:43 my_file2 drwx------ 2 boese fac 4096 Jan 19 14:44 new_dir % rmdir new_dir % ls my_file2
The previous commands allowed us to move files around in the file system, but what about modifying the structure itself?
mkdir: make directory
rmdir: remove directory
% echo hey children hey children %echo hey children hey children % echo "hey children" hey children % echo "~" ~ % echo ~ /Users/davematt %
echo command prints some text to the screen.
"to preserve text on the command line
Is this useful for anything? Sure!
What if we don’t want the output of a command to go to the screen but to a file? Or get the input to a command from a file instead of the keyboard?
Redirection allows us to change where a command gets input or sends output.
>- redirect output to a new file
>>- redirect output to an existing file and append to the end
<- redirects the input to a file (instead of the keyboard)
|- sends the output of one program to another program
% echo "hello there, children" hello there, children % echo "hello there, children" > chef % ls chef my_file2 % cat chef hello there, children % echo "hey chef" >> chef % cat chef hello there, children hey chef % date Fri Sep 21 05:38:13 MDT 2018 % date >chef % cat chef Fri Sep 21 05:38:13 MDT 2018
echoto put text into a file.
% ls chef my_file2 % ls >file_list % ls chef file_list my_file2 % cat file_list chef file_list my_file2 % pwd >> file_list % cat file_list chef file_list my_file2 /tmp
echo isn’t the only command whose output we can redirect.
% ls -l >tempfile % more <tempfile ... % more tempfile ... %
Many commands accept input from a file or a command line argument.
%ls -l > tempfile %more tempfile ... %rm tempfile % ls -l | more ... %
This is useful for combining operations without making temporary files
ls -l | morefor listing a directory with many files
man bash | moreto learn about the command line interpreter