Docsity

File Traversion in Computer Science, Cheat Sheet of Computer science

Toggle sidebar
bg1
Hands-on exercise for file traverse
โ—Change directory to โ€˜newโ€™
โ—‹cd new
โ—Copy file.txt to the parent directory
โ—‹cp file.txt ../
pf3
pf4

Partial preview of the text

Download File Traversion in Computer Science and more Cheat Sheet Computer science in PDF only on Docsity!

Hands-on exercise for file traverse

โ— Change directory to โ€˜newโ€™

โ—‹ cd new

โ— Copy file.txt to the parent directory

โ—‹ cp file.txt ../

Redirection

This command says to take the output (stdout) from file1 and append it to the bottom of file2. Redirection operators โ— (^) write to file (>) echo โ€œfooโ€ > ~/test.txt โ— (^) append to file (>>) echo โ€œbarโ€ >> ~/test.txt โ— (^) read from a file (<) sort < ~/test.txt

Piping

Another useful capability of the linux shell is the

ability to pipe output from one program to another.

To do this, you use the โ€œpipeโ€ ( | ) operator, e.g.:

cmd1 | cmd2 | cmd3 | etc.

head -n 15 Get the top 15 lines of some file or text
tail -n 15 Same thing, but bottom 15 lines
sort Sort or merge records (lines) of text and binary files
uniq -c Report or filter out repeated lines in a file with count
number
wc -l Count the number of lines in some text
more View text (method 1)
less View text (method 2)

Some more useful commands