File/Folder Quick Reference (PAL Series)

Update: These were written for my students while my role was a PAL (Peer Assisted Learning) Leader for my course, I intended to keep all the basic/intermediate commands necessary for terminal use in one place to ease the students into using Linux efficiently. I’ve kept them up just in case they’re of use to someone.

Making directories

Create a directory :

$ mkdir myDir

Create more than one directory at once :

$ mkdir dir1 dir2

Create subdirectory :

$ mkdir myDir/mySubdir

Create a subdirectory even if it’s parent does not exist :

$ mkdir -p i/don\'t/exist/yet/subdir

Creating files

Create an empty file

$ touch empty.txt

Create multiple empty files

$ touch hello.c world.c Makefile

Updating the timestamp for an existing file

$ ls -l output.exr 
-rw-r--r--. 1 tom tom 3291 Oct 30 21:23 output.exr
$ touch output.exr 
$ ls -l output.exr 
-rw-r--r--. 1 tom tom 3291 Nov 25 22:28 output.exr

Reading files

cat – Echo to terminal

$ cat hello.c # Echo the contents to the terminal
hello
world
hello
world
hello
world
hello
world
$

cat’s main purpose is actually to combine files into new files, but we can use it to print the contents too.
More info (the example uses redirection, covered here)

more – Scroll through large file (old utility)

$ more hello.c
hello
world
hello
world
--More-- 50%   # We can only move forward by pressing Enter, no scrolling back

less – Scroll through large file (modern utility, behaves like more but can scroll backwards too, use this because less is more )

$ less hello.c
hello
world
hello
world
hello.c       # We can move forward and back

What’s the difference?