Shell: Day #3
Today was the day of basic File Management, Pipes, and Redirects. So let's jump to the command's
- mkdir – create a directory for you, -p will create the parent directory if it does not exist.
- rmdir – remove the empty directory
- rm – remove the files and directory with -r.
- pushd & popd – this one is the new command I came across, it let you save the previous command and you can pop that command with popd when you require. Dirs let you list down the directories you can pop back too.
- file – tells you about the format of the file
- ?, * – these are the wildcards which help in pattern matching, '*' for any number of character and whereas ? for only one character
- | – called as pipe, it takes the output of one program and gives as an input to another program
- Redirection (<, >) – < this indicates to file to read input from, > this indicates the file to write output to.
- >> – Appends the output to the end of the file, If the file does not exist it creates a new one.
- File Descriptors – Standard Input(0), Standard Output (1), Standard Error (2), make sure to check the example below to see how you can use them
- xargs- it read a text and pass them as input to the following command
- tee – is a combination of > and | and let you copy data from the input to the output or a file
Now let see these commands in action
>> mkdir -p chess/pieces/board # create an directory for you.
>> rmdir -p chess/pieces/board # will delete whole path if no other file or dir exist
>> pushd /media/USB # will let you save this path
... # any command you run b/w
>> popd # this will get you back to the pushed path
>> dirs # list all the dir path saved
~/bash-trail ~ / ~/Code/tranzact ~/bash-trail/program
>> file shopping_list
shopping_list: ASCII text
>> whoami | rev # will reverse the output from the *whoami* output
keepdnas
>> last > last-login.txt # will save the output of login user to the file
>> wc < last-login.txt # will pass the text from the file as input to the *wc* command
>> program 2> file # will write the Standard error from the program to the file. **File Descriptor**
>> find /media/USB | xargs -l 3 rm -f # this will pass files for USB dir and xargs will pass the 3 filenames at a time to remove them.
>> last | tee everyone.txt | grep bob > bob.txt
# To save details of everyone’s logins and save Bob’s in files also.