File Commands

How to list a directory in linux

1
$ ls

Tip: Formatted listing with hidden files ls -al. Nowadays most of the terminals come with ll command to do the trick.

How to change to a directory in linux

1
$ cd ashokma

Tip: Just entering cd will get you home. ^_^

How to show current working directory in linux

1
$ pwd

How to create a directory in linux

1
$ mkdir ashokma

Tip: -p option with the above command, creates directories as needed like mkdir -p ashokma/ashkeys/sojiro

How to place the input into the file in linux

1
2
3
4
5
6
7
8
$ cat >ashkeys
How are we doing today?
Good.
# Ctrl + C to exit

$ cat ashkeys
How are we doing today?
Good.

Tip: Comes in handy to quickly take notes. \O/

How to output the contents of a file in linux

1
$ more ashkeys.txt

Tip: Use head ashkeys.txt to output the first 10 lines of the file and tail ashkeys.txt to output the last 10 lines of the file.

How to create or update a file in linux

1
$ touch ashkeys.txt

Tip: As it says it can just be used to touch a file (simply update the timestamp) to make it look like updated recently. /O\

How to delete a file or directory in linux

1
2
$ rm ashkeys.txt
$ rm -r ashokma

Tip: Use force option -f if necessary.

How to copy contents of a file or directory to the other in linux

1
2
$ cp source.txt target.txt
$ cp -r source target

How to move file in linux

1
$ mv ashkeys.txt ashokma/

Tip: Also widely used to rename a file quickly as mv oldname.txt newname.txt

1
$ ln -s ashkeys.txt shortcut_to_ashkeys.txt