Linux Basic Command Tutorial

Sometimes you can be babied with graphical operating systems sometimes, and when you get suddenly reduced to a text console you may panic but hopefully the below commands will get you out of a bind.

File listings

To get a list of files that are located in the current directory type ls You can get a more extensive listing by typing ls -la Which will give you access restrictions, who owns the file, file size, creation date, and of course the file name as well.

Copying, Moving and Deleting files

Before editing any major system file its a good idea to copy it and back it up, move it out of the way, or delete troublesome files. To copy a file you would type in cp mainfile backupfile This will take the file "mainfile" and copy its contents to a file called "backupfile"

Move a file, which can also rename a file, type mv file1 file2 This will move "file1" to "file2", you can combine this with the file system navigation how to and move a file into another directory by mv test1 backupdir This moves the file "test1" into the "backupdir" directory.

To delete a file type the following command....Please note!!! once you delete a file there is no going back!!!!! rm oldfile This will delete/remove the file "oldfile" from the current directory

File system Navigation

Sometimes you need to move about the filesystem into different directories. Sometimes the working directory automatically comes up as your prompt, if so great if not type in pwd (print working directory) to find out where your to. Combine this with a ls -la command and you know where you are and where you can navigate. To move into a directory type cd dir1 This will move you into the "dir1" directory to access the files within it. When you want to go back, move out of that directory and return to where you were type cd .. The two periods are represtentative of the directory above the one you are in now, much the same way that DOS does for those familiar with navigating the windows system. If you kept repeating that command eventually it would move you to the highest directory in the file system. Moving up one directory each time you enter the command.

Searching for file(s)

We all get lost, so do files and so do you when you are looking for files. Thats where the "find" command comes in handy. To search for a file which is located on any part of the file system type find / -name lostfile This will look for the file "lostfile" in the file system and once found tell you where it is located, you can then use the cd commands you have learned above to guide you to where that hard to find file is. But sometimes you cant remember the entire filename for those times use "*" in the search to help you out by typing find / -name notsure* This will find and tell you where every file that starts out with "notsure" is, much the same you can put the "*" anywhere you need to help you find a file find / -name *.txt To find any file that ends with a ".txt" or find / -name docu*ent To find any file that starts with "docu" and ends with "ent" You can get quite extensive to help limit your search for the exact file you need.

Making and Removing directories

To create a directory type mkdir testdir This will create a directory called "testdir" within the directory you are currently in. Once created you can use the ls, cd and other commands above to manipulate the files inside. To remove a directory type rmdir uselessinfo This will remove/delete the directory called "uselessinfo". If that directory has files contained in it the directory will not delete and instead will pop up an error. If you wish to delete both the directory and any contents in it then you must use the command rmdir uselessinfo -R

File permissions

Linux in general is very security minded, as such it will not let you execute or run programs, edit files, create files or anything along that nature if you do not have the rights (security privledges) to do so. All of the commands below have to be done as root or as a owner of the file or directory in question To change the owner of the file "addresses" to user "jason" chown jason addresses If you wanted everyone in the group that jason belongs in to have access to that same file you would type chgrp group_name addresses (where group_name is the name of the actual group) Some find it easier to use the numerical way of modifiying security rights on a file, use the guide below to assist you Setting file permissions is a vital key to system security, here is a breakdown of how to do it correctly. The syntax for giving access is chmod ### filename. The ### is a 3 digit number which gets added together based on who gets access and how much, see chart below.

400 Owner has read permission
200 Owner has write permission
100 Owner has execute permission
040 Group has read permission
020 Group has write permission
010 Group has execute permission
004 All users have read permission
002 All users have write permission
001 all users have execute permission

Add together the desired access and use that number with the command above, for instance say we would like to give the owner of file "booklist" read and write access, but to all other users only give read access. The access right would total 400+200+4=604; and thus the resulting command would be chmod 604 booklist