Command Line Flashcards
What is $echo ?
It repeats the argument you type in with a new trailing newline character
What does the flag in $echo -n mean?
No new trailing newline character for the echo command
e.g. $echo Hello World => Hello World => $ e.g. $echo -n Hello World =>Hello World $
Does $echo “Hello World” -n works to eliminate new trailing newline character?
No. Flag always comes before arguments.
What does it mean:
$cd /
Change directory to ROOT directory.
NOTE: there’s a space in front of “/”
How to go back to your home directory in CLI?
$cd ~
What does it mean:
$pwd
It shows you your current directory is at.
pwd = Print Working Directory
What does it mean:
$ls
It shows you the files and directory under your current directory
ls = LiSt directory
What does it mean:
$ mkdir This is good
It creates a new directory under the directory you’re at
** You should name the new directory in the arguments
mkdir = Make Directory
What does it mean:
$touch abc.txt
This command creates a new file (*not directory) in the current directory
** type the file name and its file type in the arguments
abc.txt = a text file named “abc”
How to rename a file (named “toy.txt”)?
$ mv toy.txt toy2.txt
How does the pattern of $ mv works?
$ mv [source] [destination]
1) if you want to change the file name, determine the source file name and write the new name in destination.
2) if you want to move a file to another directory - specify you source file name and write the destined directory in the destination (**it does not apply to move from a subdirectory back to parent directory, see point 3) (file directory needs to have slash behind file name, e.g. tmp/)
3) You can even take a file in a directory under your current directory back to your current directory; and then rename it (if you only move and no rename, still need to type in the original name).
e.g. $ mv tmp/example1.txt example2.txt
$ mv tmp/example1.txt example1.txt
How to go back to the parent directory?
$ cd ..
.. = two dots
How to remove a file (e.g. “abc.txt”)?
$ rm abc.txt
How to remove a directory (e.g. “Tealeaf”)
$ rm -r Tealeaf
*Remember to add the flag -r for recursive delete of a directory; it’s different from just deleting a file.
How to exit from content listing command like $ man or $ less ?
type q
What does $ cat do?
It prints out all contents of a file
see also: $ head / $ tail / $ more / $ less
What does $ head do?
It prints out the first few lines of a file
see also: $ cat / $ tail / $ more / $ less
What does $ tail do?
It prints out the last few lines of a file
see also: $ more / $ cat / $ head / $ less
What does $ more do?
It prints out the content of a file but only fills one screen worth at a time
In Linux/Unix CLI, what does “/” mean?
1) Root directory
2) Separator when listing directories
In Linux/Unix CLI, what does “.” mean?
The current directory
=> also as “./”
In Linux/Unix CLI, what does “..” mean?
The directory one level up
=> also as”../”
In Linux/Unix CLI, what does “../..” mean?
The directory two levels up
In Linux/Unix CLI, what does ~ mean?
Home diretory
In Linux/Unix CLI, what does “*” mean?
The splat/ glob operator.
=> represents “any characters”
e.g. ls /*e
list all files (not directories) that ends with “e”
e.g.2 mv ./* ../
=> move all files in current directory to parent directory
How to create a nested set of directories in your home directory: cli-tmp > parents > children > grandchildren
mkdir -p ~/cli-tmp/parents/children/grandchildren
Which one represents one directory up?
/..
../
../
How to copy a directory with files (e.g. phone) and change the name (e.g. eight) at once?
$ cp -r phone eight
How to list all files, including hidden ones
$ ls -a
All hidden files are named with a dot as first letter.
Hence, hidden files are also named dotfiles
How to list hidden only files?
$ls -d .*
.* => all dotfiles / hidden files
How to set environment Variables on the fly?
2 methods: set and then execute everywhere; set for a specific command at the same line
1)
$ CALIFORNIA=’CA’
$ echo $CALIFORNIA
2)
$ CALIFORNIA=’CA’ env
this method only sets variable to $env
*quote the value of variable, especially if there is special character in the value.
**no space between equal sign and value
What will it do: $ top
It shows your computer working environment like CPU usage, programs you are using, etc.