Directory commands

Change directory

research:~$ cd Documents/codenet.github.io/teaching/col-100/01
research:~/Documents/codenet.github.io/teaching/col-100/01$

List all files

research:~/Documents/codenet.github.io/teaching/col-100/01$ ls
Makefile a.out    io.c     linux.md vim.md

List all files in long format

research:~/Documents/codenet.github.io/teaching/col-100/01$ ls -l
total 48
-rw-r--r--  1 research  staff    24 Mar  4 16:50 Makefile
-rwxr-xr-x  1 research  staff  4248 Mar  4 18:52 a.out
-rw-r--r--  1 research  staff   578 Mar  4 18:52 io.c
-rw-r--r--  1 research  staff    59 Mar  4 18:53 linux.md
-rw-r--r--  1 research  staff  1045 Mar  4 18:45 vim.md

Go up one folder

research:~/Documents/codenet.github.io/teaching/col-100/01$ cd ..
research:~/Documents/codenet.github.io/teaching/col-100$ ls
01

Go back to previous folder

research:~/Documents/codenet.github.io/teaching/col-100$ cd -
/Users/research/Documents/codenet.github.io/teaching/col-100/01
research:~/Documents/codenet.github.io/teaching/col-100/01$

File commands

Create a new file

research:~/Documents/codenet.github.io/teaching/col-100/01$ echo hello > file
research:~/Documents/codenet.github.io/teaching/col-100/01$ ls -l
total 48
-rw-r--r--  1 research  staff    24 Mar  4 16:50 Makefile
-rwxr-xr-x  1 research  staff  4248 Mar  4 18:52 a.out
-rw-r--r--  1 research  staff     6 Mar  4 18:54 file
-rw-r--r--  1 research  staff   578 Mar  4 18:52 io.c
-rw-r--r--  1 research  staff    59 Mar  4 18:53 linux.md
-rw-r--r--  1 research  staff  1045 Mar  4 18:45 vim.md

Quickly seeing file contents

Macbook-Pro-2:01 research$ cat file
hello

List but show newest file last

research:~/Documents/codenet.github.io/teaching/col-100/01$ ls -lrt
total 48
-rw-r--r--  1 research  staff    24 Mar  4 16:50 Makefile
-rw-r--r--  1 research  staff  1045 Mar  4 18:45 vim.md
-rw-r--r--  1 research  staff   578 Mar  4 18:52 io.c
-rwxr-xr-x  1 research  staff  4248 Mar  4 18:52 a.out
-rw-r--r--  1 research  staff    59 Mar  4 18:53 linux.md
-rw-r--r--  1 research  staff     6 Mar  4 18:54 file

Rename file

research:~/Documents/codenet.github.io/teaching/col-100/01$ mv file x
research:~/Documents/codenet.github.io/teaching/col-100/01$ ls -lrt
total 48
-rw-r--r--  1 research  staff    24 Mar  4 16:50 Makefile
-rw-r--r--  1 research  staff  1045 Mar  4 18:45 vim.md
-rw-r--r--  1 research  staff   578 Mar  4 18:52 io.c
-rwxr-xr-x  1 research  staff  4248 Mar  4 18:52 a.out
-rw-r--r--  1 research  staff    59 Mar  4 18:53 linux.md
-rw-r--r--  1 research  staff     6 Mar  4 18:54 x

Move file

research:~/Documents/codenet.github.io/teaching/col-100/01$ mv x ../
research:~/Documents/codenet.github.io/teaching/col-100/01$ ls ..
01 x
research:~/Documents/codenet.github.io/teaching/col-100/01$ mv ../x .
research:~/Documents/codenet.github.io/teaching/col-100/01$ ls
Makefile a.out    io.c     linux.md vim.md   x

Open file for editting (more about vim)

Macbook-Pro-2:01 research$ vim x

Use esc :q! to exit out of vim

Copy file

Macbook-Pro-2:01 research$ cp x y
Macbook-Pro-2:01 research$ ls -lrt
total 48
-rw-r--r--  1 research  staff    24 Mar  4 16:50 Makefile
-rw-r--r--  1 research  staff  1045 Mar  4 18:45 vim.md
-rw-r--r--  1 research  staff   578 Mar  4 18:52 io.c
-rwxr-xr-x  1 research  staff  4248 Mar  4 18:52 a.out
-rw-r--r--  1 research  staff    59 Mar  4 18:53 linux.md
-rw-r--r--  1 research  staff     6 Mar  4 19:06 x
-rw-r--r--  1 research  staff     6 Mar  4 19:07 y

Remove file

research:~/Documents/codenet.github.io/teaching/col-100/01$ rm x
research:~/Documents/codenet.github.io/teaching/col-100/01$ rm y
research:~/Documents/codenet.github.io/teaching/col-100/01$ ls -lrt
total 48
-rw-r--r--  1 research  staff    24 Mar  4 16:50 Makefile
-rw-r--r--  1 research  staff  1045 Mar  4 18:45 vim.md
-rw-r--r--  1 research  staff   578 Mar  4 18:52 io.c
-rwxr-xr-x  1 research  staff  4248 Mar  4 18:52 a.out
-rw-r--r--  1 research  staff    59 Mar  4 18:53 linux.md

Compiling and running programs

Compile

research:~/Documents/codenet.github.io/teaching/col-100/01$ gcc io.c

Run

research:~/Documents/codenet.github.io/teaching/col-100/01$ ./a.out

Makefile

research:~/Documents/codenet.github.io/teaching/col-100/01$ cat Makefile
all:
	gcc io.c
	./a.out
research:~/Documents/codenet.github.io/teaching/col-100/01$ make
gcc io.c
./a.out

Miscellaneous

yes

research:~/Documents/codenet.github.io/teaching/col-100/01$ yes hi
hi
hi
hi
hi

Use Ctrl + c to break commands

ASCII art

research:~/Documents/codenet.github.io/teaching/col-100/01$ cowsay hi
 ____
< hi >
 ----
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

research:~/Documents/codenet.github.io/teaching/col-100/01$ banner -w 40 hi
          #                         #
          ###########################
          ###########################
          ###########################
                        #
                        ##
                        ##
          ################
          ###############
          ############
          #              #
          ################    ####
          ################    ####
          ################     ##

Pipes

Macbook-Pro-2:01 research$ banner -w 40 hi | lp