Sunteți pe pagina 1din 7

Basic Linux Commands

This list comes courtesy of Mark Rais, senior editor reallylinux.com

NOTICE this is ONLY the Basic list. I also offer a list of commands for:
Beginning Server Administration
Files and Permissions
Directory navigation
Commands for Guru-Wannabees

It is my hope that these beginner Linux commands will provide you with a good start to your Linux
command line adventures.

TIP 1:
All of these commands should work from your command prompt (regardless which shell you're
using). Just in case some folks were not aware, you MUST press enter to invoke the command

TIP 2:
For this summary, please note that the EX: stands for example and is not part of the command.
Commands are denoted in courier type font.

TIP 3:
If you need help understanding what the options are, or how to use a command, try adding this to
the end of your command: --help

For example, for better understanding of the df command's options, type:


df --help
Brought to you by Reallylinux.com
Command Summary Use
Type cd followed by the name of a directory to access that
directory.
Keep in mind that you are always in a directory and allowed access
to any directories hierarchically above or below. You may also
benefit from reviewing my directory commands page.Ex:
cd games
Use cd to change directories
If the directory games is not located hierarchically below the
current directory, then the complete path must be written out. Ex:
cd /usr/games
To move up one directory, use the shortcut command. Ex:
cd ..

Type clear to clean up your command prompt window.


This is especially helpful when you are typing lots of commands
and need a clean window to help you focus.Ex:
Use clear to clear the clear
command prompt This is also useful when you are getting ready to type a rather long
command and do not wish to become confused by other details on
the screen.

Use date to set your Type date followed by the two digit month, the two digit date, the
two digit time, and two digit minutes. The syntax is easy enough
and resembles this: MMDDhhmm
This command is helpful but must be used when superuser or
logged in as root.

You can get more help with administrator commands by clicking


server's date and time this link. Note that if you don't use root, you will get an "Operation
not permitted" reply.As root user you can use the
command such as:
date 11081300
The above command will set the server date and time to the 11th
month (November), the 8th day, at 1:00pm.

Typing df provides a very quick check of your file system disk


space.
Type df -h to get a more easily readable version of the output.
Use df to check disk space Notice that this command will include all applicable storage such as
your hard disk/s (hda, hdb etc.) and your server SWAP file (shm).
To list disk space including filesystem type:
df -h -T

Typing finger allows you to see who else is on the system or get
detailed information about a person who has access to the system.
Use finger to see who's Type finger followed by the name of a user's account to get
information about that user. Or, type finger and press enter to see
on the system
who's on the system and what they are doing. Ex:
finger johndoe

Yep, you guessed it, typing logout will log your account out of the
system.
Type logout at the prompt to disconnect from your Linux machine
Use logout to quit using or to logout a particular user session from the system. Keep in mind
that although rudimentary, leaving your critical account logged on
the system
may be a security concern. We always recommend promptly using
logout when you are finished using your root account! Ex:
logout

Use ls to list files and Type ls to see a list of the files and directories located in the
directories current directory. If you’re in the directory named games and you
type ls, a list will appear that contains files in the games directory
and sub-directories in the games directory. Examples:
ls Mail
ls /usr/bin
Type ls -alt to see a list of all files (including .rc files) and all
directories located in the current directory. The listing will include
detailed, often useful information. Examples:
ls -alt
ls -alt /usr/bin
If the screen flies by and you miss seeing a number of files, try
using the |more at the end like:
ls -alt |more

* In Bash (Linux shell) often the abbreviated command L is


available. To get a verbose listing of files and directories you could
therefore simply type: l

Type man followed by a command to get detailed information


about how to use the command. Ex:
Use man to pull up man ls
information about a Linux Type man -k followed by a word to list all of the commands and
command descriptions that contain the word you specified. Ex:
man -k finger

Type more followed by the name of a text file to read the file’s
Use more to read the contents. Why do we exmphasize using this on a "text" file?
Because most other types of files will look like garbage! Ex:
contents of a file
more testfile.txt

Typing nano will start a basic text editor on most Linux systems.
Type nano followed by the filename you wish to edit. This basic
editor is quick and easy to use for beginners. However, it is very
Use nano to start a text important that you also learn about other text editors available on
editor Linux and UNIX systems. Click on this link to learn about others
like emacs, vi, and pico. Ex:
nano /etc/security/access.conf

Type passwd and press enter. You'll see the message Changing
password for yourname.
At the Old password: prompt, type in your old password .
Then, at the Enter new password: prompt, type in your new
password .
The system double checks your new password. Beside the Verify:
Use passwd to change your prompt, type the new password and press again.
current password
Create a secure password that combines parts of words and
numbers. For instance, your dog's name may be Rufus. He may
have been born in 1980. Create a password that uses parts of both
the name and date of birth, such as 80rufuS. Note the use of at least
one capital letter. This is a fairly secure password and easy to
remember.

Use pwd to list the name of Type pwd and hit enter. You'll see the full name of the directory
you are currently in. This is your directory path and is very handy.
This is especially handy when you forget which directory you’ve
your current directory
changed to and are trying to run other commands.

Want more? Perhaps you're ready for our Commands


for Guru Wanna-bees or review the
Beginner commands for Server Administration.

These commands brought to you by Reallylinux.com.

Manipulating Files
http://www.reallylinux.com/docs/files.shtml
This page is intended to help the Linux newbie come up to speed on core file handling commands including file permissions.
Brought to you by Mark Rais, our senior editor. To read comands for Directories please click here.

Included in this section are the commands needed to copy, delete, move, and rename files. Security and
permissions are also reviewed below in the chmod command.

A beginner? Then it may help you to type the command ls -alt to list all of your current
files and directories before you start, so you can see your directory and files listed.

Already have experience? Then please skip to Commands for Guru Wanna-bees.

NOTE:
All of these commands should work from your command prompt (regardless which shell you're
using). And of course, if they don't work or help you, I apologize.

Manipulating Files - Linux Commands


Command Summary Use
chmod The chmod command allows you to alter access
rights to files and directories. All files
and directories have security permissions
that grant the user particular groups’ or all
other users’ access.

To view your files' settings, at the shell


prompt type: ls -alt

You should see some files with the following


in front of them (an example follows):
total 4
drwxrwsr-x 7 reallyli reallyli 1024 Apr 6 14:30 .
drwxr-s--x 22 reallyli reallyli 1024 Mar 30 18:20 ..
d-wx-wx-wx 3 reallyli reallyli 1024 Apr 6 14:30
content
drwxr-xr-x 2 reallyli reallyli 1024 Mar 25 20:43 files

What do the letters mean in front of the


files/directories mean?
r indicates that it is readable (someone can
view the file’s contents)
w indicates that it is writable (someone can
edit the file’s contents)
x indicates that it is executable (someone
can run the file, if executable)
- indicates that no permission to manipulate
has been assigned

When listing your files, the first character


lets you know whether you’re looking at a
file or a directory. It’s not part of the
security settings. The next three characters
indicate Your access restrictions. The next
three indicate your group's permissions, and
finally other users' permissions.

Use chmod followed by the permission you


are changing. In very simple form this would
be:
chmod 755 filename
The example above will grant you full rights,
group rights to execute and read, and all
others access to execute the file.

# Permission
7 full
6 read and write
5 read and execute
4 read only
3 write and execute
2 write only
1 execute only
0 none

Still confused? Use the table above to define


the settings for the three "users." In the
command, the first number refers to your
permissions, the second refers to group, and
the third refers to general users.

Typing the command: chmod 751 filename

gives you full access, the group read and


execute, and all others execute only
permission.

cp Type cp followed by the name of an existing


file and the name of the new file.

Ex:
cp newfile newerfile
To copy a file to a different directory
(without changing th
e file’s name), specify the directory instead
of the new
filename. Ex:
cp newfile testdir
To copy a file to a different directory and
create a new file name, you need to specify a
directory/a new file name. Ex:
cp newfile testdir/newerfile
cp newfile ../newerfile
The .. represents one directory up in the
hierarchy.

file Type file followed by the name of an existing


file in the directory.

Ex:
file emergency3_demo.exe

OUTPUT: MS-DOS executable (EXE)

This command allows you to figure out what


the file type is and how to use it. For
instance the command will tell you whether it
is an executable, a compressed file and which
type, or something unusual.

This command is simplistic, but often can


allow you to determine why a file does not
respond the way you expect.

mv Type mv followed by the current name of a


file and the new name of the file.

Ex:
mv oldfile newfile

Type mv followed by the name of a file and


the new directory where you'd like to place
the file. Ex:
mv newfile testdir
This moves the file named newfile to an
existing directory named testdir. Be certain
you’re specifying a directory
name or the mv command alters the name of the
file instead of moving it.

rm Type rm followed by the name of a file to


remove the file.

Ex:
rm newfile
Use the wildcard character to remove several
files at once. Ex:
rm n*
This command removes all files beginning with
n.
Type rm -i followed by a filename if you’d
like to be prompted before the file is
actually removed. Ex:
rm -i newfile
rm -i n*
By using this option, you have a chance to
verify the removal of each file. The -i
option is very handy when removing
a number of files using the wildcard
character *.

This list only has items related to files, but this link will take you to the page related to
commands for directories.

S-ar putea să vă placă și