HELLO GUYS WELCOME BACK TO HACKER HEAVEN..I HOPE YOU ENJOYED MY PREVIOUS ARTICLE ...
i hope at this point, we are ready for some real work! This article will introduce the following
commands:
● cp – Copy files and directories
● mv – Move/rename files and directories
● mkdir – Create directories
● rm – Remove files and directories
● ln – Create hard and symbolic links
These five commands are among the most frequently used Linux commands. They are used for manipulating both files and directories.
Now, to be frank, some of the tasks performed by these commands are more easily done with a graphical file manager. With a file manager, we can drag and drop a file from one directory to another, cut and paste files, delete files, etc. So why use these old command line programs ?
The answer is power and flexibility. While it is easy to perform simple file manipulations with a graphical file manager, complicated tasks can be easier with the command line programs. For example, how could we copy all the HTML files from one directory to another, but only copy files that do not exist in the destination directory or are newer than the versions in the destination directory? Pretty hard with a file manager. comparetively it's easy with the command line:
command :
cp -u *.html destination
-u : update (means it will copy only those files which are not present in the destination or which are newer than the preset files)
**don't be panic we will discuss it in further .
actually this is an example for explaining my point that why we all have to use command line instead of the GUI mode .but i promise you that you will be able to do all these stuff very easily by command line after today's reading and following the instructions...
so without wasting the time let's start ..
mkdir – Create Directories
The mkdir command is used to create directories. It works like this:
command :
mkdir directory...
A note on notation:
When three points follow an argument in the description of a command
(as above), it means that the argument can be repeated, thus:
command:
mkdir dir1
would create a single directory named “dir1”, while
commmand :
mkdir dir1 dir2 dir3
would create three directories named “dir1”, “dir2”, and “dir3”.
note : today we dealing with 3 other commands, every commands description is matches same to same about 90%...like in command mkdir have one or more than one similar as this command cp (copy ) have same not only this but also ln(making link) command have same description as in this...so it make quite easy to learn the theory behind the all command but how to implement in real we will see it in video as well as screeshots practical image...that will explain a lot to understand the commands..
cp – Copy Files And Directories
The cp command copies files or directories. It can be used two different ways:
cp item1 item2
to copy the single file or directory “item1” to file or directory “item2”
AND
cp item... directory
like i explain before these three dots represent that it can copy multiple items (either files or directories) into a directory.
Useful Options And Examples
Here are some of the commonly used options (the short option and the equivalent long
option) for cp:
-a or --archive
Copy the files and directories and all of their attributes,
including ownerships and permissions. Normally,
copies take on the default attributes of the user
performing the copy.
-i or --interactive
Before overwriting an existing file, prompt the user for
confirmation. If this option is not specified, cp will
silently overwrite files.
-r or --recursive
Recursively copy directories and their contents. This
option (or the -a option) is required when copying
directories.
-u or --update
When copying files from one directory to another, it only
copies files that either doesn't exist, or are newer than the
existing corresponding files, in the destination directory.
-v or --verbose
display massage when task is done. (eg:-copying is sucessfull) ....
cp Examples
-cp file1 file2
Copy file1 to file2. If file2 exists, it is overwritten
with the contents of file1. If file2 does not exist, it
is created.
-cp -i file1 file2
Same as above, except that if file2 exists, the user is
prompted if and only if the file is overwritten.
actiually here i just try to explain that first time when i copy /passwd file from dir1 to dir2 it just copy it without any pop-up massage,but next time i try to copy same file to dir2 it will ask about overwriting option..
-cp file1 file2 dir1
Copy file1 and file2 into directory dir1. dir1 must
already exist.
here in this screenshot i try to use relative path name that point i already explain in my previous articles..REMEMBER THAT..?
-cp dir1/* dir2
Using a wildcard, all the files in dir1 are selected and then copied
into dir2.
condition dir2 must already exist.
-cp -r dir1 dir2
Copy the contents of directory dir1 to directory
dir2. If directory dir2 does not exist, it is created
and, after the copy, will contain the same contents
as directory dir1.
If directory dir2 does exist, then directory dir1 (and
its contents) will be copied into dir2.
for this i just delete dir2 from my directory and try to copy dir1 to dir2 which is not exit.
mv – Move And Rename Files
The mv command performs both file moving and file renaming, depending on how it is used. In either case, the original filename no longer exists after the operation. mv is used in much the same way as cp:
mv item1 item2
to move or rename file or directory “item1” to “item2” or:
mv item... directory
to move one or more items from one directory to another.
Useful Options And Examples
mv shares many of the same options as cp:
-i, --interactive
Before overwriting an existing file, prompt the user for
confirmation. If this option is not specified, mv will
silently overwrite files.
-u, --update
When moving files from one directory to another, only it will
move files that either doesn't exist, or are newer than the
existing corresponding files in the destination
directory.
-v, --verbose
Display informative messages as the move is done...
mv Examples
here note that what these example i gonna explain is same as copy commands ..i already show you lots of screenshots..but now i am not gonna be repeat the same task...you know it little bit laziness...haha...try it self..
ok look up the examples and the description given below..
mv file1 file2
Move file1 to file2. If file2 exists, it is overwritten
with the contents of file1. If file2 does not exist, it
is created. In either case, file1 ceases to exist.
mv -i file1 file2
Same as above, except that if file2 exists, the user is
prompted before it is overwritten.
mv file1 file2 dir1 Move file1 and file2 into directory dir1. dir1 must
already exist.
mv dir1 dir2
If directory dir2 does not exist, create directory
dir2 and move the contents of directory dir1 into
dir2 and delete directory dir1.
If directory dir2 does exist, move directory dir1
(and its contents) into directory dir2.
rm – Remove Files And Directories
The rm command is used to remove (delete) files and directories:
command :
rm item...
** here look only first command rest are not explaining this point..haha..again i just copy above image here...laziness..
where “item” is one or more files or directories.
Useful Options And Examples
Here are some of the common options for rm:
-i, --interactive
Before deleting an existing file, prompt the user for
confirmation. If this option is not specified, rm will
silently delete files.
-r, --recursive
Recursively delete directories. This means that if a
directory being deleted has subdirectories, delete them
too. To delete a directory, this option must be specified.
-f, --force
Ignore nonexistent files and do not prompt. This
overrides the --interactive option.
-v, --verbose
Display informative messages as the deletion is
performed.
rm examples
rm file1
Delete file1 silently.
rm -i file1
Same as above, except that the user is prompted for
confirmation before the deletion is performed.
rm -r file1 dir1
Delete file1 and dir1 and its contents.
rm -rf file1 dir1
Same as above, except that if either file1 or dir1 do
not exist, rm will continue silently.
Be Careful With rm!
Unix-like operating systems such as Linux do not have an undelete command.
Once you delete something with rm, it's gone. Linux assumes you're smart and
you know what you're doing.
Be particularly careful with wildcards. Consider this classic example. Let's say
you want to delete just the HTML files in a directory. To do this, you type:
rm *.html
which is correct, but if you accidentally place a space between the “*” and the
“.html” like so:
rm * .html
the rm command will delete all the files in the directory and then complain that
there is no file called “.html”.
Here is a useful tip. Whenever you use wildcards with rm (besides carefully
checking your typing!), test the wildcard first with ls. This will let you see the
files that will be deleted. Then press the up arrow key to recall the command and
replace the ls with rm.
ln – Create Links
The ln command is used to create either hard or symbolic links. It is used in one of two ways:
ln file link
to create a hard link, and:
ln -s item link
to create a symbolic link where “item” is either a file or a directory.
Srry guy's i have to quiet this one without screenshot i have lots of college work...(ye sale college wale bhi na bachho ko chain se nhi jeene dete...assignment pe assignment..assignment pe assignment..bs rh jata hai assignment...#sunnydeol..haha, all these fuc*** thing...only indians understad this...LOL)
but i promise i will write another article only performing all the commands i just not cover here....
ok..,these are the some theory for today article...
ya, but before we going to the practical mood..let's talk about an important topic 'wild-card'...a shell feature that makes these commands so powerful. Since the shell uses filenames so much, it provides special
characters to help you rapidly specify groups of filenames. These special characters are called wildcards. Using wildcards (which is also known as globbing) allow you to select
filenames based on patterns of characters. The table below lists the wildcards and what they select:
* Matches any characters
? Matches any single character
[characters] Matches any character that is a member of the set characters
[!characters] Matches any character that is not a member of the set
characters
[[:class:]] Matches any character that is a member of the specified
class
NOTE : [[:class:]], actually what is class ? here..after seeing this you will understand it very well...
[:alnum:] Matches any alphanumeric character
[:alpha:] Matches any alphabetic character
[:digit:] Matches any numeral
[:lower:] Matches any lowercase letter
[:upper:] Matches any uppercase letter
these are the some shortcut it make feel you annoiyng but believe me by the time goes in practice it will become very easy for you to use to manage your file or searching your file whatever..
here i am giving some more helpful example that make easy to understand the meaning of the given wildcars(shortcuts).
* All files
g* Any file beginning with “g”
b*. txt Any file beginning with “b” followed by
any characters and ending with “.txt”
Data??? Any file beginning with “Data” followed
by exactly three characters
[abc]* Any file beginning with either an “a”, a
“b”, or a “c”
BACKUP.[0-9][0-9][0-9] Any file beginning with “BACKUP.”
followed by exactly three numerals
[[:upper:]]* Any file beginning with an uppercase letter
[![:digit:]]* Any file not beginning with a numeral
*[[:lower:]123] Any file ending with a lowercase letter or
the numerals “1”, “2”, or “3”
here another note that 'Wildcards Work In The GUI Too'
Wildcards are especially valuable not only because they are used so frequently on the command line, but are also supported by some graphical file managers.
● In Nautilus (the file manager for GNOME), you can select files using the
Edit/Select Pattern menu item. Just enter a file selection pattern with wildcards and the files in the currently viewed directory will be highlighted for selection.
● In some versions of Dolphin and Konqueror (the file managers for KDE),
you can enter wildcards directly on the location bar. For example, if you want
to see all the files starting with a lowercase “u” in the /usr/bin directory, enter
“/usr/bin/u*” in the location bar and it will display the result.
i hope this is not place to perform the practical of all these stuff what we learn today...so i have to upload another article based on these concepts so please refer to my next article ,for the further reading..
read my next article ....
ZEROCOOL
SIGN OUT