Command structure | command [option]... [argument]... |
---|---|
Commands | man , pwd , ls , cd |
Pathnames | / , ~ , . , .. |
Notes
/
, or a user's home directory.
~
or ~
username
.
and the parent directory with ..
pwd
, ls
, cd
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. man
and 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 %
The 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 Wed Dec 25 16:22:12 MST 2024 % date >chef % cat chef Wed Dec 25 16:22:12 MST 2024
echo
to 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 | more
for listing a directory with many files
man bash | more
to learn about the command line interpreter
man
or info
more
or cat
cp
, mv
, rm
, mkdir
, rmdir
echo
"
>
, >>
, |
<
Modified: 2017-08-25T12:31 User: Guest Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |