Breaking News

Basic Linux Commands 101

0 0

When accessing your favorite Linux distribution it is always good to have a reference around to get you around in the terminal (command line interface). Why you ask? Because every now and then you may need to do something that cannot be done using the graphical user interface. When this happens will need to pop open a terminal and issue a few commands to get things done!
Here are a few to get you started!!

1. cd = change directory — This command gets you to whatever directory you type in directly after the command.
For example: At the command prompt type cd /home and hit enter. You are now in the home directory. Now type cd /root and hit enter. You are now in the /root folder. If you are in /home/nugod and want to go to /home simply type cd .. and hit enter. You will go up one directory.

2. ls = this one list the files in the current directory. Type ls and hit enter and all of the non-hidden files will be displayed (files starting with a . are considered hidden). Type ls -a and hit enter and all files will be displayed. Typing ls -l will show additional information about the files.

3. mkdir = creates a directory — This command should be used when you want to create a directory. Type mkdir /home/-insertyourusernamehere-/newdirectory and hit enter. A new directory called newdirectory will be created in your home folder.

4. ln -s = makes a symbolic link — This command is good for creating a link to a folder or file in one directory when it is actually located in another. For example: Lets say you are in your home directory and you access a file in the /var/www directory called list.html quite often, at the command prompt you would type ln -s /vaw/www/list.html list.html and hit enter. This would create a link in your home directory called link.html. When you open this file (with a text editor or browser or anything else) it will actually be opening the file in /var/www.

5. rmdir = this command removes a directory or folder that is empty. Lest say you have a directory in your home folder called oldjunk that you no longer use and it is empty, type rmdir /home/-insertyourusernamehere-/oldjunk and hit enter. The directory will be removed.

6. rm = this command removes a file, directory or symbolic link. Lets say you had the same directory described in the rmdir command but it has files in it. Type (this will require superuser privledges) rm -dr /home/-insertyourusernamehere-/oldjunk and hit enter. The directory and all of the files in it will be deleted. If you wanted to remove junk.txt from your home directory (single files do not require super user as long as you have permissions to delete them) you would type rm /home/-insertyourusernamehere-/junk.txt and hit enter. The file would be deleted.

7. pwd = pwd means “print working directory”. Typing pwd and hitting enter will show you the working directory you are in. If you are ever unsure what directory you are in simply type it in and hit enter.

8. cp = this is the command used in linux to copy a file or directory from one location to another. Its usage is simple: cp [source] [location]. cp /home/username/filename /etc/filename would copy filename from the /home/username directory to the /etc directory. cp -i /home/username/filename /etc/filename would prompt you about overwriting /etc/filename if it already exists. If you don’t use the -i option cp will overwrite an existing file without asking. To copy a directory and all of the files in that directory you would use cp -r /home/username/directoryname /etc/ and hit enter. This would copy directoryname from /home/username to /etc leaving the directory name intact.

9.mv = This is the move command in linux. It can be used to move files from one location to another as well as renaming files. mv /home/username/filename /etc/filename would move filename from /home/username to /etc. Like cp you can use the -i option to prompt you in the case of an overwrite. To rename a file use mv like this: mv /home/username/filename /home/username/newfilename. You are actually moving filename to newfilename but it functions as rename.

10. touch = This command basically does what it sounds like, it touches a file. If you touch /path/to/filename and hit enter the access and modification times for that file will be updated to the current time. If the file does not exist it will be created as an empty file. To create a blank file in your home directory type touch /home/yourusername/filename and hit enter. If filename does not exist it will be created. If it exists then the last time it was accessed and the last time it was modified will be updated.

These are just a few basic commands to get you started using linux. The commands and options listed above are to described doing specific tasks but, the commands have other options. To see more detailed options for any of these commands type commandname –help and hit enter (i.e. ln –help will show you the available for the ln command). It is highly recommended that you read these extra options. Basic Linux Commands 102 will continue with more linux commands and what they do.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *