Working With Files

touch

Create a new file or change the modified date of an existing file→.

touch filename.txt

cp

Copy file to a path→

cp filename1.txt filename2.txt

# use -r to copy recursively (for example, all nested directories and files)

cp -r dir1 dir2

mv

Move file to a different location, or rename. →

# renaming 
mv filename1.txt filename2.txt

# moving
mv filename.txt dir

less

Show the contents of a file with pagination. →

less filename1.txt

# use <SPACE> to page down
# use <b> to page up
# use <UP>,<DOWN> to navigate by line
# use <q> to quit
# use </> to search

more

Show the contents of a file with pagination. →

more filename1.txt

cat

Show all of the contents of a file →

cat filename1.txt

Show the contents of the start of a file. →

head filename1.txt

tail

Show the contents of the end of a file. →

tail filename1.txt

# show changes realtime!
tail -f filename.txt

# display last 5 lines
tail -n5  filename.txt

rm

Remove a file. →

rm filename1.txt

# also... to remove everything recursively (and ignore
# confirmation)... use this (be careful with it!)

rm -rf filename1.txt

Wildcard Matching

# copy all gifs into the archive folder
cp *.gif archive

# move all gifs into the archive folder
mv *.gif archive

wc

Count the number of lines, words or bytes in a file. →

# count the number of lines, words, and bytes in a file
wc filename.txt

# count the number of lines in a file
wc -l filename.txt

Activity: Drills!

Entering commands flash cards x 3 (use set 3)

We’ll do this together, then try downloading it yourself:

  1. Download drills.py to the home directory
  2. Type python drills.py
  3. When prompted for a number, enter 3
  4. CTRL-C quits

Lab

Working With Files

Activity: Drills!

Entering commands flash cards x 3 (use set 123)

We’ll do this together, then try downloading it yourself:

  1. Download drills.py to the home directory
  2. Type python drills.py
  3. When prompted for a number, enter 123
  4. CTRL-C quits

Permissions, Editing, Date and Time