Saturday , 25 October 2014

Tutorial: Basic Linux console commands

There comes a time in our lives, when we are faced with the all mighty Linux, we want it or not (ok, maybe some of you are just lucky ). Either you want to install it at your place, help a friend who purchased a computer with Linux installed or you just purchased a Linux dedicated server for hosting, the console will greet you first and we need to learn some basic Linux console commands.

In my opinion, the Linux console is still the most powerful tool a Linux user or admin can have, although today’s Linux distributions are very easy to use, almost “console free”.

Here is a list with some essential Linux console commands, you can’t live without.

The ls command

The ls command is a listing command, almost the same as the dir command from DOS, but with more options attached. Basically with the ls command you can list the contents of the present directory or subdirectory.

ls -a : List all the files in directory/subdirectory, without the hidden files

ls -l : Displays a more detailed listing of the present directory, including size, owner, date, permissions etc

The rm command

The rm command is used to remove files or directories. Please be advised that the rm commanda doesn’t remove empty directory unless “forced”

rm dirname or rm filename : Removes the specified directory or the specified file

rm -l dirname/filename : Removes the specified directory/file with confirmation

rm -rf dirname : Removes the directory recursively, by forcing ( -f stands for force ). With this command you can delete the contents of a directory even if it has subdirectories or files.

rm -r dirname : Removes the directory even if it is empty

The cp command

This command copies directories or files from a spot to another ( stands for copy ).

It’s main syntax is:

cp source_full_path destination_path – source is the file or directory you want to copy

Example: cp /home/user/hello.tar.gz /home/user2/

cp -r source_dirname destination_dirname – this command copies an entire directory to another directory (recursively)

The mkdir command

The mkdir command creates a new directory (make directory). It’s main syntax is mkdir dirname

The pwd command

This command returns the path in which you are present at that moment

The su command

su stands for switch user and it’s used to change the current user and log to another. Most frequently this command is used when you want to configure Linux or modify it, by logging to root

su root

The man command

The man command is probably the most important command for a Linux beginner, with the desire to learn. Using man, it returns the manual of the command asked as following:

man cp – returns the manual for the cp command, with syntax and so on

man ls – returns the manual for the ls command with syntax

The cat command

This command displays the contents of a file: cat file

The ps command

This command shows the processes running on the machine as following:

ps – shows your own processes

ps -ef – shows all processes

ps -fu user – shows the processes of the user user

The top command

The top command is a Windows Taks Manager like command, showing all processes on the machine, users for each process, cpu usage and memory usage for each process

The du and df commands

du – (disk usage) shows the disk usage of the current path, displaying all the files and their size

df -h – displays the disk usage of the entire machine, in a more simple and better way.

With these commands, you should become friendly with the Linux console in no time, allowing you to complete your basic tasks and learning Linux at the same time.

About Cezar Renta

  • jay

    not enough!!!!!!!!!

  • jay

    not enough!!!!!!!!!

  • Wade Meyer

    I’m happy the Linux console is a powerful tool.  But I haven’t figured out how to get to it to try the commands you show us.  I have Ubuntu the latest version.
    I’m trying to follow the directions that Java.com gave me to install their 52mb plug-in.  Thanks.

Scroll To Top