Basic Linux Commands

Most average users use Linux with GUI (Graphical User Interface) but if you are familiar with Windows command prompt, you will see many similarities with Linux commands. Here at TheGeekNotes we present you some Basic Linux Commands to get you started.

mkdir – make directories

  • Usage
  • mkdir [OPTION] DIRECTORY
  • Options
  • Create the DIRECTORY(ies), if they do not already exist.
  • Mandatory arguments to long options are mandatory for short options too.
  • -p, parents  no error if existing, make parent directories as needed
  • -m, mode=MODE  set permission mode (as in chmod), not rwxrwxrwx – umask
  • -v, verbose  print a message for each created directory
  • -p, parents  no error if existing, make parent directories as needed
  • -version output version information and exit
  • -help display this help and exit

mv- change the name of a directory

  • Type mv followed by the current name of a directory and the new name of the directory.
  • Ex: mv testdir newnamedir

cd – change directories

  • Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.

rmdir - Remove an existing directory

rm -r

  • Removes directories and files within the directories recursively.

pwd – print working directory

  • will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page

chown – change file owner and group

  • Usage
  • chown [OPTION] :GROUP FILE
  • chown [OPTION] OWNER[:[GROUP]] FILE
  • chown [OPTION] –reference=RFILE FILE
  • Options
  • Change the owner and/or group of each FILE to OWNER and/or GROUP. With –reference, change the owner and group of each FILE to those of RFILE.
  • -h, no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can         change the ownership of a symlink)
  • -from=CURRENT_OWNER:CURRENT_GROUP
  • change the owner and/or group of each file only if its current owner and/or group match those specified here.  Either  may  be  omitted,  in which case a match is not required for the omitted attribute.
  • -no-preserve-root do not treat `/’ specially (the default)
  • -preserve-root fail to operate recursively on `/’
  • -c, changes like verbose but report only when a change is made
  • -dereference affect the referent of each symbolic link, rather than the symbolic link itself
  • -R, -recursive operate on files and directories recursively
  • -f, -silent, -quiet  suppress most error messages
  • -reference=RFILE use RFILE’s owner and group rather than the specifying OWNER:GROUP values
  • -v, -verbose output a diagnostic for every file processed
  • -L     traverse every symbolic link to a directory encountered
  • -H     if a command line argument is a symbolic link to a directory, traverse it
  • -P     do not traverse any symbolic links (default)

ls – Short listing of directory contents

  • -d        list the name of the current directory
  • -a        list hidden files
  • -g        show group ownership of file in long listing
  • -F        show directories with a trailing ‘/’
  • executable files with a trailing ‘*’
  • -i        print the inode number of each file
  • -t        sort by time modified instead of name
  • -R        list all subdirectories encountered
  • -l        long listing giving details about files  and directories

chmod – change file access permissions

  • Usage
  • chmod [-r] permissions filenames
  • r  Change the permission on files that are in the subdirectories of the directory that you are currently in.        permission  Specifies the rights that are being granted. Below is the different rights that you can grant in an alpha  numeric format.filenames  File or directory that you are associating the rights with Permissions
  • w – Write or edit the file.
  • r – Read the file.
  • a – All.
  • o – Other.
  • g – Group that owns the file.
  • u – User who owns the file.
  • x – Execute or run the file as a program.
  • Numeric Permissions:
  • CHMOD can also to attributed by using Numeric Permissions:
  • 040 read by group
  • 400 read by owner
  • 001 execute by anybody
  • 010 execute by group
  • 100 execute by owner
  • 002 write by anybody
  • 020 write by group
  • 200 write by owner
  • 004 read by anybody (other)

cp – Copy files

  • cp -i myfile yourfile
  • With the “-i” option, if the file “yourfile” exists, you will be prompted before it is overwritten.
  • cp  myfile yourfile
  • Copy the files “myfile” to the file “yourfile” in the current working directory. This command will create the file “yourfile” if it doesn’t exist. It will normally overwrite it without warning if it exists.
  • cp -dpr srcdir destdir
  • Copy all files from the directory “srcdir” to the directory “destdir” preserving links (-poption), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another dir
  • cp -i /data/myfile
  • Copy the file “/data/myfile” to the current working directory and name it “myfile”. Prompt before overwriting the  file.

ln – Creates a symbolic link to a file.

  • ln -s test symlink
  • Creates a symbolic link named symlink that points to the file test Typing “ls -i test symlink” will show the two files are different with different inodes. Typing “ls -l test symlink” will show that symlink points to the file test.
  • wall - Prints a message to each user except those who’ve disabled message reception. Type Ctrl-D to end the message.
  • w – Prints the current system users.
  • uptime – Prints the system uptime.
  • traceroute host – Uses echo requests to determine and print a network path to the host.
  • top – Prints a display of system processes that’s continually updated until the user presses the q key.
  • telnet host – Opens a login session on the specified host.
  • sync – Completes all pending input/output operations (requires root privileges).
  • split file – Splits a file into several smaller files. The command has many arguments; see the online documentation
  • sort files – Sorts the specified files. The command has many useful arguments; see the online documentation.
  • reboot – Reboots the system (requires root privileges).
  • sleep timeCauses the command interpreter to pause for the specified number of seconds.
  • shutdown minutes
  • shutdown -r minutes
  • Shuts down the system after the specified number of minutes elapses (requires root privileges). The -r option causes the system to be rebooted once it has shut down.
  • man title
  • man section title – Prints the specified man page.
  • ping host – Sends an echo request via TCP/IP to the specified host. A response confirms that the host is operational.
  • mail – Launches a simple mail client that permits sending and receiving email messages
  • killall program
  • killall – signal program
  • Kills all processes that are instances of the specified program or sends the specified signal to all processes that are instances of the specified program.
  • kill -l
  • Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.
  • kill – signal process_ids
  • .
  • ispell files – Checks the spelling of the contents of the specified files.
  • head files – Prints the first several lines of each specified file.
  • ftp hostname
  • Opens an FTP connection to the specified host, allowing files to be transferred. The FTP program provides subcommands for accomplishing file transfers; see the online documentation.
  • free  – Displays the amount of used and free system memory.
  • finger users – Prints descriptions of the specified users.
  • find path -name pattern -print
  • Searches the specified path for files with names matching the specified pattern (usually enclosed in single quotes) and prints their names. The find command has many other arguments and functions; see the online documentation.
  • file files – Determines and prints a description of the type of each specified file.
  • fg
  • fg jobs – Brings the current job (or the specified jobs) to the foreground.
  • dmesg – Prints the messages resulting from the most recent system
  • boot.
  • diff file1 file2 – Compares two files, reporting all discrepancies. Similar to the cmp command, though the output format differs.
  • cmp file1 file2 – Compares two files, reporting all discrepancies. Similar to the diff command, though the output format differs.
  • clear – Clears the terminal screen.
  • cat files – Prints the contents of the specified files.
  • cal month year – Prints a calendar for the specified month of the specified year.

bg

  • bg jobs Places the current job (or, by using the alternative form, the specified jobs) in the background, suspending its execution so that a new user prompt appears immediately. Use the jobs command to discover the identities of background jobs.
  • wc – Print byte, word, and line counts whereis – Report all known instances of a command
  • cat – Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping. less – Opposite of the more command
  • more – Allows file contents or piped output to be sent to the screen one page at a time

slocate -u

This command builds the slocate database. It will take several minutes to complete this command.This command must be used before searching for files, however cron runs this command periodically  on most systems.locate whereis Lists all files whose names contain the string “whereis”. directory.

  • locate – A fast database driven file locator.
  • Share/Bookmark
Posted by Admin On July - 8 - 2010 Linux

2 Responses to “Basic Linux Commands”

  1. how to get over an ex boyfriend says:

    Some subscribers just don’t get it, like my neighbor who couldn’t see the practical substance of this section on your article “… contentschmod &#8211 change file access permissionscp &#8211 Copy files ln &#8211 Creates a …” this is it, you just smashed it down pal.

Leave a Reply