Working with the Command Line: Basic Linux Commands | SUSE Communities

Working with the Command Line: Basic Linux Commands

Share
Share

The following article is part of a series of articles that provide tips and tricks for Linux newbies – or Desktop users that are not yet experienced with regard to certain topics. This series intends to complement the special edition #30 “Getting Started with Linux” based on openSUSE Leap, recently published by the Linux Magazine, with valuable additional information.

This article has been contributed by Lingshan Zhu, Software Developer Data Center Management, SUSE.

 

 

One of the biggest hurdles for a lot of people to adopt Linux is the fear to use the command line. True, the terminal can be a scary thing when you look at it for the first time. But it also comes with many advantages, and gives you much more control over your operating system and the actions you can take. And, if you just dare to engage with it, you will see it is way less scary than you thought. Thus, the goal of this article is to help you “survive” in the command line world, and to pilot your first steps (yes, also if you are a “light” Linux desktop user, you probably can learn something …), by giving you an overview of the most frequently used commands.

The Terminal

First, you need to know how to start a terminal. For beginners, it’s recommended to install Linux with a GUI interface – in our case it is KDE. All examples are of course based on openSUSE Leap 42.3.

You can press the windows key on your keyboard. Type “Terminal” in the popup search box, then click the icon with a “Terminal” title. OK, that was easy, now you have a running terminal. Let’s see what you can do with it! And always remember that lower case and capital letters matter when typing commands.

ls

To list directory contents, type ls in the terminal.

This command will return a list of all contents of a directory. Running  ls /home will show all contents stored in your /home directory, while just running the command ls will show the contents under your current directory. There are two useful additional options for the ls command:

  • -l:  will display a long list with additional useful information like permissions, file size and last modification time.
  • -a: will show hidden files or sub directories

pwd

The pwd command stands for “print working directory and will show you the name of your current working directory – that means “where you are” right now.

cd

With the cd command, which stands for “change directory”, you can change your current working directory.

For example, if I am currently working in the directory /home/lszhu and I want to switch to /etc/, I just can change my current working directory using the command cd /etc.

rm

The command rm is used for deleting files or directories. For example, rm ./foo.txt will delete the foo.txt file in your current directory. To delete directories, use the -r option, which stands for “recursive”. An example would be rm -r ./test. This will delete the directory named “test” with all files and sub directories in it.

clear

The clear command will clear the terminal screen. This command can be useful if you worked for quite a while on one and the same terminal. You might want to clean it because your screen might seem “messy”. Just run clear – this lets you “wipe out” all words in the terminal.

mv

You can move your files or directories to somewhere else with the command mv . For example, mv ./test /var will move the file test from the current working directory to the /var directory. mv can also be used to rename a file: mv ./test ./foo will rename the file originally named “test” to “foo”.

mkdir

The command <i>mkdir<i> means “make directory” and allows for the creation of new directories.

Something like mkdir /home/lszhu/test_dir will create a new directory named test_dir under the /home/lszhu directory. There is also a useful option -p. This means “make parent directories as needed”. Imagine you have an empty directory /home/lszhu, then you want to create a directory called “workspace” and a directory “docs” under workspace. You can create the directories one by one in these steps:

mkdir workspace
cd ./workspace
mkdir docs

But using the -p option is more efficient: mkdir -p ./workspace/docs will create the “docs” directory, and as the parent directory workspace doesn’t yet exist, mkdir will create it as well within this same command.

cp

cp is a command used to copy files or directories. Imagine you have a file named “scst.conf” in the current directory, and you want to copy it to the directory /var<i>. In this case, the cp command can help you by copying the file with cp ./scst.conf /var. If you want to copy a directory, the -r option can help you together with the cp command. As an example, cp -r ./test /var will copy the directory named test to /var with all files and sub directories in it. After that, you will see a directory /var/test, which has the exact same contents as the original test directory. You can also easily rename a directory or file when executing cp. For example, cp ./test /var/foo will first copy your test directory to /var, but it will then rename it to a new directory name foo under the /var directory.

su and sudo

The su command can help you to switch to superuser. The superuser is the system user who has all permissions to be able to perform administrative tasks. Some commands require superuser privileges. As an example, only the superuser can shut down the computer. When you use the command sudo as prefix, you can promote your privileges to superuser temporarily. As an example, you can type sudo poweroff to run the command to shut down the computer.

poweroff and reboot

The command poweroff shuts down the running system, while the command reboot cares for a reset of your system. Both commands require superuser privileges.

man

The man command displays the manual of the command you provided. As an example, man ls opens the manual of the command ls. To exit the manual, just press for “quit”. You can use man for every command mentioned in this article to display the respective manual.

 

Of course not all of the many many cool Linux commands can be listed here – but these are the most frequently used ones and hopefully will be from help during your Linux journey.

Now keep in mind: no matter which command you might want to use, the man command might become your best friend in the Linux world. So, for example if you want to know how to compress or decompress files using tar, or how to login to another computer using ssh, just “man” these commands them!

Have a lot of fun!

 

Share

Comments

  • Avatar photo J. S. Evans says:

    A little known tool that I get a lot of use out of is: apropos.

    Need to read a man page but don’t know which one you need?

    ~> apropos samba
    Crypt::SmbHash (3pm) – Perl-only implementation of lanman and nt md4 hash functions, for use in Samba style smbpassw…
    cupsaddsmb (8) – export printers to samba for windows clients
    eventlogadm (8) – push records into the Samba event log store
    lmhosts (5) – The Samba NetBIOS hosts file
    log2pcap (1) – Extract network traces from Samba log files
    net (8) – Tool for administration of Samba and remote CIFS servers.
    pdbedit (8) – manage the SAM database (Database of Samba Users)
    samba (7) – A Windows AD and SMB/CIFS fileserver for UNIX
    samba-regedit (8) – ncurses based tool to manage the Samba registry
    smb.conf (5) – The configuration file for the Samba suite
    smbpasswd (5) – The Samba encrypted password file
    smbstatus (1) – report on current Samba connections
    vfs_aio_fork (8) – implement async I/O in Samba vfs
    vfs_aio_linux (8) – implement async I/O in Samba vfs using Linux kernel aio calls
    vfs_aio_pthread (8) – implement async I/O in Samba vfs using a pthread pool
    vfs_audit (8) – record selected Samba VFS operations in the system log
    vfs_extd_audit (8) – record selected Samba VFS operations
    vfs_full_audit (8) – record Samba VFS operations in the system log
    vfs_readonly (8) – make a Samba share read only for a specified time period
    vfs_recycle (8) – Samba VFS recycle bin
    vfs_time_audit (8) – samba vfs module to log slow VFS operations

  • Leave a Reply

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

    Avatar photo
    85,371 views
    Meike Chabowski Meike Chabowski works as Documentation Strategist at SUSE. Before joining the SUSE Documentation team, she was Product Marketing Manager for Enterprise Linux Servers at SUSE, with a focus on Linux for Mainframes, Linux in Retail, and High Performance Computing. Prior to joining SUSE more than 20 years ago, Meike held marketing positions with several IT companies like defacto and Siemens, and was working as Assistant Professor for Mass Media. Meike holds a Master of Arts in Science of Mass Media and Theatre, as well as a Master of Arts in Education from University of Erlangen-Nuremberg/ Germany, and in Italian Literature and Language from University of Parma/Italy.