SUSE Blog

Working with the Command Line: Basic Linux Commands

chabowski

By: chabowski

November 20, 2017 3:23 am

Reads:1,895

Comments:2

Score:Unrated

Print/PDF

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!

 

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.
Loading...

Tags: , , , , , , , , ,
Categories: openSUSE, SUSE Linux Enterprise, Technical Solutions

Disclaimer: As with everything else in the SUSE Blog, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

2 Comments

  1. By:J. S. Evans

    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

Comment

RSS