Using
Linux
1. Creating general users
You can use useradd and passwd commands to create general users.
For example, creating a new user account named wsuser.
Assign a password for the acount wsuser.
2. Getting Help
-
use man command to find out about how to use commands
-
man stands for "manual", a series of online "pages" which can
tell you the purpose of many commands.
-
Todo: check the man pages of the command man
3. Walking around the Linux Directories
-
Where you are? To find where you are, use the command
-
Command pwd return the absolute path of your current working
directory. every absolute path are started with '/'. '/' means the
root (top) of the Linux filesystem. Every accessible directories and files
are stored uder the root directory to form a hierarchical file structure
(just like a tree, you may just call it a directory tree).
-
To change your current working directory to the place you want to go, use
the change directory command
-
Relative path is the path relative to your current directory. If
you want to move up, you can change directory to '..' (the parent directory).
$ cd /etc/X11
$ pwd
/etc/X11
$ cd /etc
$ pwd
/etc
$ cd /etc/X11
$ cd ..
$ pwd
/etc
|
4. Looking Around
-
To check the contents of a directory or a file in a directory, use the
list command
-
Options used with ls. Yoy can view the full list by reading the
ls man page (man ls)
-
-a, --all: List all files in the directory, including the hidden
files (files starting with '.').
-
-l, --long: Lists details about contents, including permission (modes),
owner, group, size, creation date, whether the file is linked to somewhere
else on the system and where its link points.
-
-F, --classify: Adds a symbol to the end of each listing. These
symbols include / to indicate a directory, @ to indicate a symbolic link
to another file, * to indicate an executable file.
-
-R, --recursive: Lists the contents of all directories (below the
current directory) recursively.
-
Todo:
$ cd /etc/X11
$ ls
$ ls -F
$ ls -a
$ ls -la
$ ls -lR
$ ls -la /etc
$ ls -la /etc | more
$ ls -la /etc | less
|
Working with Files and Directories
-
To create a directory under the current directory, use make directory command
mkdir.
cd /tmp
mkdir test
ls -F
cd test
|
-
To create a file, you can use any text editor. Such a pico, gedit,
kedit, or simply cat.
-
To copy a file, use the copy command
$ cp test test1
$ cp /etc/X11/XF86Config .
$ ls
|
-
To rename a file or a directory, use the move command
$ mv test1 test2
$ ls
$ cd ..
$ mv temp temp1
$ cd temp1
$ ls
|
-
To delete a file, use the remove command
-
To delete a directory, use the remove directory command
$ rm test
$ ls
$ cd ..
$ rmdir temp1
$ ls
|
5. Cleaning the Screen
-
To cleanup the screen, use the clean command
-
If your terminal screen have been screwed up by strange characters, you
can reset the terminal windows by the reset command
try this
-
cat /bin/ls
-
^C [Control]-C
|
6. Using cat
-
command cat, short for "concatenate", means concatenate files
and print on the standard output.
-
Standard input and standard output direct input and output
(often referred to as I/O) to the user. If a program reads from standard
input, it will, by default be reading from the keyboard. If a program writes
to standard output, by default it will be writing to the screen.
-
Try cat command and type anything on the screen
-
To return to the shell prompt, type ^D (Control-D).
Redirection
-
Unix shells and utilities are developed in a consistent way which conform
to certain guidelines. This is important because by following the guidelines,
tools can easily be integrated together to accomplish larger tasks. And
remember that building a program to achieve a large task is a complex process.
The resulting program cab be inflexible and buggy.
-
Every interactive tools should have input and output. In the Unix shell
environment, you can redirect input or output of a program from or to a
file.
-
By redirect standard output and command cat, you can create
short file without a text editor.
$ cat > file1
from file1
^D
$ cat > file2u
from file2
^D
$ cat file1
$ cat file2
|
-
you can use cat to combine two files and rediecting the output
the a new file.
$ cat file1 file2
$ cat file1 file2 > file3
$ cat file3
|
-
the output redirection > is used to create a file or replace the
contents of the existing file with the output from the previous command.
To append the output to the end of the exists file without overwrite its
existing contents, you should use the append symbol '>>'.
$ cat file1 > file3
$ cat file2 >> file3
$ cat file3
|
-
you can also the standard input for a command from a file using standard
input redirection '<'.
-
in the above example, without the filename as the parameter, command cat
will check input from standard input. And in this case, the standard input
have been rediected to the file file3, so the contents of file3
will be displayed.
7. Pipes
-
Pipe is an important shell functions to integrate tools to make
it working together.
-
Pipes connect the stardard output of one command to the standard input
of another command.
$ ls -la /etc | less
$ ls -la /etc | grep hosts | less
|
8. Puting Commands Together
-
To enter multiple commands in a single line, you can separate the commands
with a semicolon ';'. In this case, the commands are separated just as
you enter it separately the shell prompt.