Introduction to Unix
Unix contains many hundred of commands but you will probably use just 10 or so to achieve most of what you want to do.
U1. The Terminal
A ‘terminal’ is the common name for the program that does two main things. It allows you to type input to the computer (i.e. run programs, move/view files etc.) and it allows you to see output from those programs.
Task U1.1
There will be many situations where it will be useful to have multiple terminals open and it will be a matter of preference as to whether you want to have multiple windows, or one window with multiple tabs (there are keyboard
shortcuts for switching between windows, or moving between tabs).
U2. Your first Unix command
Unix keeps files arranged in a hierarchical structure.It’s important to note that you will always be “in” a directory when using the terminal. The default behavior is that when you open a new terminal you start in your own ’home” directory (containing files and directories that only you can modify).
ls command
Four things noted :
1.different outputs depending on your computer
2. Unix command prompt: root@kali:~#
3. directories or files
4. it produces a new command prompt
The ls
command is used to list the contents of any directory, not necessarily the one that you are currently in.
U3 : The Unix tree
A tree analogy is often used when describing computer filesystems.When you log in to a computer you are working with your files in your home directory, and this will nearly always be inside a ‘Users’ directory. On many computers there will be multiple users.
U4: Finding out where you are
pwd
will Print the Working Directory and that’s pretty much all this command does:
The first forward slash that appears in a list of directory names always refers to the top level directory of the file system (known as the root directory). The remaining forward slash (between ‘users’ and ‘clmuser’) delimits the various parts of the directory hierarchy.
U5: Getting from ‘A’ to ‘B’
To change directories, we use the cd
command:
U6: Root is the root of all evil
When you specify a directory that starts with a forward slash, you are referring to a directory that should exist one level below the root level of the computer.
U7: Up, up, and away
Two dots ..
are used in Unix to refer to the parent directory of wherever you are. Use two sets of the ..
operator, separated by a forward slash,to navigate up two levels in the file system in one go:
U8: I’m absolutely sure that this is all relative
change to a directory based on its absolute location. Sometimes it is quicker to change directories using the relative path, and other times it will be quicker to use the absolute path.
U9: Time to go home
Unix uses the tilde character as a short-hand way of specifying a home directory.
U10: Making the ls
command more useful
Command-line options in Unix are specified by using a dash (‘-’) after the command name followed by various letters, numbers, or words.
Task U10.1
ls -R “Recursion”, 递归列出目录文件
U11: Man your battle stations!
Unix command has an associated ‘manual’ that you can access by using the man command.
man ls
man cd
man man
When you are using the man command, press space
to scroll down a page, b
to go back a page, or q
to quit. You can also use the up and down arrows to scroll a line at a time.
U12: Make directories, not war
make a directory
Task U12.1
Practice creating some directories and navigating between them using the cd command. Try changing directories using both the absolute as well as the relative path (see section U8).