700 likes | 2.34k Vues
Linux Basic Commands. CS 302. Listing files and directories. ls (list) To find out what is in your home directory, type: % Is. Please Note: the default directory is cygwin /home/username where username is your computer username. $ ls –m
E N D
Linux Basic Commands CS 302
Listing files and directories • ls (list) To find out what is in your home directory, type: % Is Please Note: the default directory is cygwin/home/usernamewhere username is your computer username • $ ls –m • To list files across the page, separated by commas. • $ ls ~ • List the contents of your home directory by adding a tilde after the ls command. • $ ls / • List the contents of your root directory. (Your root directory is Cygwin)
Making Directories • mkdir (make directory) To make a subdirectory in the current directory you are in. Example : to make a subdirectory called newdir in your home directory, type : % mkdir newdir Now you can see the directory you have just created (newdir), by using Is command.
Changing to a different directory • cd (change directory) To change the current working directory to another. The current working directory may be thought of as the directory you are in, i.e. your current position in the file-system tree. To change to the directory you have just made, type % cd newdir Type ls to see the contents (which should be empty)
Changing to a different directory (Cont.) • (..) means the parent of the current directory, so typing % cd .. will take you one directory up the hierarchy (back to your home directory). Try it now. • Note: typing cd with no argument always returns you to your home directory. This is very useful if you are lost in the file system.
Pathnames • pwd (print working directory) To find out the pathname of your current directory , type : % pwd
Displaying the contents of a file on the screen • cat (concatenate) The command cat can be used to display the contents of a file on the screen. Type: % cat filename.txt • head The head command writes the first ten lines of a file to the screen. Type: % less science.txt • tail The tail command writes the last ten lines of a file to the screen. Type: % tail science.txt
Create empty files • touch Filename When used without any options, touch creates new files for any file names that are provided as arguments. ex.: The following command would create three new, empty files named file1, file2 and file3: touch file1 file2 file3 You can also provide an extension to the file you want to create. Ex: touch file.txt
Movingfiles The command mv moves or renames files. • To rename file: % mv oldfilenamenewfilename % mv abc1 abc2 It will rename the file abc1 to a new name abc2 • To move a file to a directory. use (mv) in the following form: %mv filename directoryname It will move the file into the named directory keeping its old name. %mv abc2 /home/ubuntu/test • Move abc2 file to test directory
Copying files • cp This command makes a copy of file1 in the current workingdirectory and calls it file2. % cp file1 file2
Deleting files • rm filename
Compress files • gzipfilename compresses files, so that they take up much less space. Usually text files compress to about half their original size, but it depends very much on the size of the file and the nature of the contents. There are other tools for this purpose, too (e.g. compress), but gzip usually gives the highest compression rate. Gzip produces files with the ending '.gz' appended to the original filename
Uncompress files • gunzipfilename uncompress files compressed by gzip.