linux commands
The pwd Command
pwd, which stands for present working directory. This command shows the name and location of the current directory, which is the directory (also called a folder on some operating systems) in which the user is currently working. All that is necessary in order to use this command is to type the word pwd in at the keyboard as follows and then press the ENTER key:
The ls Command
ls is another of the most basic and frequently used commands on Unix-like operating systems. It is equivalent to DIR on MS-DOS systems, and it lists the contents of a directory. When used just by itself, it provides a list of the names of the objects (i.e., files, directories and links) in the current directory, i.e.,
ls
for hidden files
ls -a
Another common option for ls is -s, which shows the size of each file (but not directory 3) in kilobytes. This option is often used together with the above two options as
ls -als
The cd Command
The last of what are perhaps the three most basic commands on Unix-like operating systems is cd, which is used to change the current directory. This is equivalent to the CD and CHDIR commands in MS-DOS.
Thus, for example, to change the current directory to the /bin directory, the following would be used:
cd /bin
Likewise, to change to the root directory, the following would be used:
cd /
Any user can return to its home directory by using a tilde
as the argument for cd. A tilde is a short, wavy, horizontal line that
represents the home directory of the current user, and this character is
located in the upper left hand corner on most standard English language
keyboards. That is, any user can return immediately to its home
directory by typing the following and then pressing the ENTER key:cd ~
The touch Command
The touch command is the easiest way to create new, empty files. Its syntax is
touch [option] file_name(s)
No options are required for basic file creation. Thus, for example, to create a new file named file1 within the current directory
(i.e., the directory in which the user is currently working), all that
is necessary is to type the following command and then press the ENTER
key:
touch file1
The mkdir Command
The mkdir command is is used to create new directories (which are also referred to as folders in some operating systems). Its syntax is
mkdir [option] directory_name(s)
The rm Command
The rm command is often the most efficient way to remove files and directories. Its syntax is
rm [option] file_name(s)
Thus, for example, to delete file1, the following would be used:
rm file1
This can become tedious if it is desired to delete a large number of files, such as all of the files within a directory. A much more efficient (but also more dangerous) way to do this is to use wildcards, which can be used to represent anything. For example, the star (*) character is a wildcard that can represent any string (i.e., any sequence of characters). Therefore, the following would delete every file in the current directory:
rm *
And the following would remove everything in the directory dir1:
rm dir1/*
As another illustration of the great versatility that wildcards add to
the command line, the following would delete all files in the current
directory that have a file name extension of .html but would leave all others intact:
rm *.html
The rmdir Command
The rmdir command provides another way to remove empty directories. Its syntax is:
rmdir [option] directory_names
When used without any options, rm will delete any empty directories whose names are supplied as arguments.The cp Command
The cp command is used to copy files and directories. The copies become independent of the originals (i.e., a subsequent change in one will not affect the other).
cp's basic syntax is
cp [options] name new_name
If a file with the same name as that assigned to the copy of a file (or
a directory with the same name as that assigned to the copy of a
directory) already exists, it will be overwritten. By default, cp only
copies files and not directories.
When a copy is made of a file or directory, the copy must have a different name than the original if it is to be placed in the same directory as the original. However, the copy can have the same name if it is made in a different directory. Thus, for example, a file named file4 which resides in the current directory could be copied with the same name into another directory, such as into /home/john/, as follows:
cp file4 /home/john/file4
Any number of files can be simultaneously copied into another directory
by listing their names followed by the name of the directory. cp is an intelligent
command and knows to do this when only the final argument is a
directory. The files copied into the directory will all have the same
names as the originals. Thus, for example, the following would copy the
files named file5, file6 and file7 into a directory named dir6:
cp file5 file6 file7 dir6
cp's -r option, which can also be written with an upper case -R,
allows directories including all of their contents to be copied. Thus,
for example, the following command would make a copy of an existing
directory called dir7, inclusive of all it contents (i.e., files, subdirectories, their subdirectories, etc.), called dir8:
cp -r dir7 dir8
The mv Command
The mv command is used to rename and move files and directories. Its basic syntax is:
mv [options] source target
The mv Command
The mv command is used to rename and move files and directories. Its basic syntax is:
mv [options] source target
for example, to rename a file called file8 to file9, both in the current directory, the following would be used:
mv file8 file9
Detailed information (including all options) about mv as well as all of the other commands discussed above can be obtained by using their --help option.
mv --help
df reports the amount of free disk space available on each partition.
ln creates links between files.
Examples:
To make a soft (symbolic) link "hello" to the file "/home/alice/code/bin/world":
$ ln -s /home/alice/code/bin/world hello
No comments:
Post a Comment