8/25/2010

Command line basic

ls (Listing)

● This command will show you the contents of a directory.
○ls --> will show you the contents of the current directory.
○ ls /dir/name --> will show you the contents of a specified
directory.
○ ls -l --> will show you a long listing containing ownership,
permissions, time last modified, and size.
○ ls -a --> will show you all of the files in the directory, including those
starting with a .
○ ls -al --> What do you think?

[mlevan@localhost BasicCommands]$ ls -al
total 24
drwxrwxr-x 2 mlevan mlevan 4096 Apr 30 17:43 .
drwxr-xr-x 10 mlevan mlevan 4096 Apr 30 17:36 ..
-rw-rw-r-- 1 mlevan mlevan 1828 Apr 30 17:57


cd (Change Directory)


● This command will change your current working directory.
● cd --> If you just type in cd, then you will be sent to your home directory.
For example, /home/mlevan/
● cd /dir/name --> This command will send you directly into the desired
directory.
○ cd /var/log/ --> This will send us to the /var/log directory.
● What about these commands :
○ cd .
○ cd ..



cp (CoPy)


● cp filename1 filename2 --> This command will copy the first file
into the second file.
● cp Amy.txt Garret.txt
● Note that if Garret.txt is already a file, then it will be overwritten !! Be careful
with this command.
cp -i Amy.txt Garret.txt
○ If Garret.txt exists, then this command will inquire if you want to
overwrite the file.
○ If Garret.txt does not exist, then you will not be asked.
● Note that you can also add directory names to this:
● cp /home/mlevan/Amy.txt /home/guest/Garret.txt
● You can also copy files to a directory :
○ cp file1 file2 fileN directory_name
○ cp Amy.txt Garret.txt temp/
● Note that ~ can also represent your home directory. For example, say I want to
copy a file from /home/guest1/booty to the temp directory in my account:
○ cp /home/guest1/booty/blah.txt ~/temp/

Rm (ReMove)


● rm command will remove a file.
○ rm filename
● If you type in rm -i filename , then you will be asked if you really want
to remove the file.
● It is virtually impossible to regain a file after it has been removed in this
fashion


mv (MoVe)

● This is the "rename" command used in DOS.
● This command moves one filename into another filename.
○ mv filename1 filename2
●The above command automatically writes over filename2 with whatever was in filename1
○ mv -i filename1 filename2
● The above command will inquire if you really want to move the file.
● You can also move directories with this command,
○ mv dir_name1 dir_name2

touch

● This command will create a file.
○ touch filename
● If the file already exists, then touch will update the timestamp of the file.

No comments:

Post a Comment