Overview. These are commonly used on Linux systems to store settings and configuration data, and are typically hidden simply so that they don’t clutter the view of your own files. You can then edit the command before you run it by moving the cursor left and right with the arrow keys, and removing the character to the left with Backspace or the one the cursor is on with Delete. Now we'll discus about some basic linux commands with examples, you're almost always going to need those commands, so better to remember them. See what happens when you try to pass the wrong number of parameters to a command: Back to our new directories. 35 Linux Basic Commands Every User Should Know (Cheat Sheet) When following instructions you find online you should now be in a better position to spot those commands that might require greater scrutiny. pwd is an abbreviation of ‘print working directory’. Every Linux system includes a command line of one sort or another. Let’s remedy that by redirecting the output from a command so that, instead of being printed to the screen, it ends up in a new file. The wc (word count) command can tell us that, using the -l switch to tell it we only want the line count (it can also do character counts and, as the name suggests, word counts): Similarly, if you wanted to know how many files and folders are in your home directory, and then tidy up after yourself, you could do this: That method works, but creating a temporary file to hold the output from ls only to delete it two lines later seems a little excessive. Now to the command itself. But we have seen two commands that are absolute. YUM (Yellowdog Updater Modified) is an open source command-line as well as graphical based package management tool for RPM (RedHat Package Manager) based Linux systems.It allows users and system administrator to easily install, update, remove or search software packages on a systems. Think of it as the counterpoint to mkdir -p. So if you were to run rmdir -p dir1/dir2/dir3 it would first delete dir3, then dir2, then finally delete dir1. Suppose you want to go straight to your “Desktop” folder from anywhere on the disk (note the upper-case “D”). !188 Typing two exclamation points repeats your previous command.!! In an effort to reduce these problems many Linux distributions started to encourage the use of the su command. Or will it replace it entirely? Whether it’s the file name itself, GPS coordintates embedded in photos you take on your phone, or the metadata stored in an audio file, text still plays a vital role in every aspect of computing. Before we conclude this tutorial it’s worth mentioning hidden files (and folders). You can change the working directory using the cd command, an abbreviation for ‘change directory’. If anyone asks you to use su, be wary. So far we’ve only seen commands that work on their own (cd, pwd) or that have a single item afterwards (cd /, cd ~/Desktop). Many manuals Later we’ll install a useful tool to visualise the structure, but you’ve already got enough knowledge to confirm it: The “-p” that we used is called an option or a switch (in this case it means “create the parent directories, too”). Instead, there are hundreds of basic utilities that when combined offer great power to accomplish big tasks with efficiency. They’re often highly technical, but you can usually skip most of the content and just look for the details of the option or argument you’re using. Zed Shaw, author of a series of programming books, always includes a Command Line Crash Course to help new programmers get moving quickly. If you follow any instructions that tell you to run sudo su, be aware that every command after that will be running as the root user. Of course a person logged in as root is just as capable of making mistakes as anyone else. Pipe the output through wc -l to give you a clearer idea of how many hidden files and folders have been right under your nose all this time. However you launch your terminal, you should end up with a rather dull looking window with an odd bit of text at the top, much like the image below. Use the following command to bring up the WiFI interface. Let’s move it back to the working directory. On execution of the command, the users are on the system are listed in an alphabetical order. An asterisk ("*") can be used to indicate “zero or more characters”. Or you could save a lot of typing by passing a path directly to the ls command to get straight to the confirmation you’re looking for: Now suppose it turns out that file shouldn’t be in dir1 after all. Create test1.txt and test2.txt, which you can use as sample files to test out the other commands.. 1. When adding a new user there is an option to create them as an administrator, in which case they will also be able to run superuser commands with sudo. If you’re using Ubuntu the root account is disabled by default, so su with no parameters won’t work. Grep is a Linux / Unix command-line tool used to search for a string of characters in a specified file. Here you will learn the Linux command line (Bash) with our 13 part beginners tutorial. If, however, you’re intrigued by the ability to affect files in disparate parts of your hard drive with just a few keypresses, there’s still a lot more for you to learn. [ You might also like: Book review: The Linux Command Line] 3. ls -al. You should see a directory path printed out (probably something like /home/YOUR_USERNAME), then another copy of that odd bit of text. Have you noticed it changing as you move around the file system? command Bash Shortcuts CTRL-c Stop current command CTRL-z Sleep program CTRL-a Go to start of line CTRL-e Go to end of line CTRL-u Cut from start of line CTRL-k Cut to end of line CTRL-r Search history!! You can create new files and add content to them using the cat command.. On a Ubuntu 18.04 system you can find a launcher for the terminal by clicking on the Activities item at the top left of the screen, then typing the first few letters of “terminal”, “command”, “prompt” or “shell”. What’s more important is that you’ve learnt the key aspects of working with the shell. If you pass more than two arguments, the last one is taken to be the destination directory and the others are considered to be files (or directories) to move. Using man (manual) pages to find out about commands Now let’s create another copy of the file, in our working directory but with a different name. Let’s give it a go: You probably didn’t even need to type that one in to guess what would happen: two new folders, one called another and the other called folder. One important concept to understand is that the shell has a notion of a default location in which any file operations will take place. Again, it’s a small safety net to prevent you from accidentally deleting a folder full of files when you didn’t mean to. The distribution chosen for this is Ubuntu, but these commands that are about to be exposed will work on any other Linux system you might encounter. If we wanted to list them all it would clearly fill up more than a single screen. If you can’t find a launcher, or if you just want a faster way to bring up the terminal, most Linux systems use the same default keyboard shortcut to start it: Ctrl-Alt-T. Before learning the tools of a CentOS Linux Administrator, it is important to note the philosophy behind the Linux administration command line. In order to coordinate the execution of each of these programs, the user would connect to one single master program that could then be used to launch any of the others. The importance of case To manage your files, you can use either the GUI(File manager) or the CLI(Terminal) in Linux. You can think of it as saying “switch to the root directory, then follow the route from there”. You should more easily be able to tell what files they’re manipulating, or what other switches and parameters are being used. Instead it deletes them totally, utterly and irrevocably. SCP is a secure copy program to transfer files or directories between Linux hosts on the network. Given that these are just test files, however, perhaps we don’t really need three different copies of combined.txt after all. You can copy multiple files to a directory right from your terminal with this neat command. Be extra careful with case when typing in the command line. While working on the Linux command line, typing long paths, file names, and more can feel like a burden. By wrapping the user’s commands this “shell” program, as it was known, could provide common capabilities to any of them, such as the ability to pass data from one command straight into another, or to use special wildcard characters to work with lots of similarly named files at once. Using the tilde character ("~") at the start of your path similarly means “starting from my home directory”. In this tutorial, we will show you how to edit files on the command line. Don’t worry too much about which shell you have, all the content in this tutorial will work on just about all of them. The commands were also kept very terse to reduce the number of keystrokes needed, speeding up people’s use of the terminal even more. There are lots of different ways to install software on Linux systems. Telnet is a command-line tool used to connect remote host manly to test application ports connectivity. This process of piping one command into another is so commonly used that the character itself is often referred to as the pipe character, so if you see that term you now know it just means the vertical bar. Many years ago we had a problem where I worked. LinuxCommand.org is a web site that helps users discover the power of the Linux command line. With this approach of small tools chained to accomplish bigger tasks, it is simpler to make a script performing these commands, than automatically email results at regular time intervals. Whether creating files, renaming them, putting them into subdirectories or moving them around on disk, users in the 70s could do everything entirely with a textual interface. It’s safest to explicitly delete files to clear out a directory, then cd .. to the parent before using rmdir to remove it. This tutorial will teach you a little of the history of the command line, then walk you through some practical excercises to become familiar with a few basic commands and concepts. You can often tell a person who uses the command line a lot just from their file names: they’ll tend to stick to letters and numbers, and use underscores ("_") or hyphens ("-") instead of spaces. It’s fortunate for us that the Linux command line includes some powerful tools for manipulating text content, and ways to join those tools together to create something more capable still. Both have its relative advantages. Yet still text prevails as a means to organise and categorise files. Now your working directory is “/”. This speed and efficiency is one reason why this text interface is still widely used today. The command above will have created three new subdirectories inside our folder. Wget, is a part of GNU Project, the name is derived from World Wide Web (WWW).Wget is a command-line downloader for Linux … $ id uid=1000(fedora) gid=1000(fedora) groups=1000(fedora),4(adm),10(wheel),190(systemd- In older systems it was a real user, with a real username (almost always “root”) that you could log in as if you had the password. To come out of the man page, you can enter q. The superuser is, as the name suggests, a user with super powers. 20 Linux Yum Commands What is YUM? Linux has a graphical user interface and it works pretty much like the GUI's on other systems that you are familiar with such as Windows and OSX. Will the computer complain, because the file already exists? or * characters in them, too. Much as the mv command moves files, so the cp command copies them (again, note the space before the dot): Great! With that in mind, here’s the command to get rid of that pesky folder_6 and the subdirectory within it: Remember: although rm -r is quick and convenient, it’s also dangerous. The ls command is probably the first command most Linux users encounter.Those of us who hang around the command line use it day in and day out without even thinking about it. You should take particular care when using wildcards, as it’s easy to accidentally delete more files than you intended. For this reason you’ll see it used quite often in command lines. But if you’re somewhere inside your home directory, it will use “~” as an abbreviation. If you plan to use the terminal a lot, memorising Ctrl-Alt-T to launch the terminal and Ctrl-D to close it will soon make it feel like a handy assistant that you can call on instantly, and dismiss just as easily. Even if you don’t understand every single command, you should at least have an idea of where one command stops and the next begins. But as I matured as a user I found CLI (command line interface) was more efficient than fiddling with the buttons of a tool. When used with no arguments it assumes you want to change to the root user (hence the first interpretation of the name), but you can pass a username to it in order to switch to a specific user account (the second interpretation). Accessing command history and editing facilities 5. There’s a bit more going on here, but if you look at each argument at a time you should be able to work out what’s happening: With combined.txt now moved into dir2, what happens if we decide it’s in the wrong place again? But some options can reduce the security level so, if you’re asked to run snap install with any parameters other than the name of the snap, it’s worth checking exactly what the command is trying to do. To understand why, we need to look at the documentation for the uniq command. Don’t use the root account Defining, modifying, referencing, and exporting environment variables 4. The following pages are intended to give you a solid foundation in how to use the terminal, to get the computer to do useful work for you. Finally, type the new character in place, and press Enter or Return to run the command once you’re finished. First, remind yourself what the ls command is currently showing: Suppose we wanted to capture the output of that command as a text file that we can look at or manipulate further. The Linux command line is … The “/” directory, often referred to as the root directory, is the base of that unified file system. At least now you’ll understand what’s happening, even when you can’t easily see the file in your graphical tools. They’re best used when you need a reminder of a particular switch or parameter, rather than as a general resource for learning how to use the command line. To avoid re-typing each command after the first, use the Up Arrow to pull up the previous command in the history. The superuser, as the name suggests, has more powers than a normal user, so can easily wreak havoc with a badly typed command. use the command with ‘sudo’ prefix. It contains clear descriptions, command outlines, examples, shortcuts and best practice. You can repeat any of the commands from your history by typing an exclamation point ! Better to disable the root account entirely and then, instead of allowing long-lived terminal sessions with dangerous powers, require the user to specifically request superuser rights on a per-command basis. But often the instructions just require you to install software from the standard repositories, which should be safe. Let’s begin by putting our combined.txt file into our dir1 directory, using the mv (move) command: You can confirm that the job has been done by using ls to see that it’s missing from the working directory, then cd dir1 to change into dir1, ls to see that it’s in there, then cd .. to move the working directory back again. As most people use an OS with a graphical user interface (GUI) for their day-to-day computer needs, the use of a terminal emulator is a necessity for most Linux server users. It can be useful when you need to run a series of commands as the superuser, to avoid having to prefix them all with sudo, but it opens you up to exactly the same kind of problems that were described for su above. Open a terminal window and create the first file: cat >test1.txt. All it does is print out the shell’s current working directory. However from my experience, it's much easier to remember if you write them with pen on paper, rather than just typing on terminal. It’s only polite to leave your computer in the same state that we found it in, so as a final step, let’s remove the experimental area that we were using earlier, then double-check that it’s actually gone: As a last step, let’s close the terminal. Repeat last command!abc Run last command starting with abc!abc:p Print last command starting with abc!$ Last argument of previous command ALT-. Even system configuration files can often be viewed (with cat or less) as a normal user, and only require root privileges if you need to edit them. In short, root can do just about anything, skipping easily round the safeguards that are usually put in place to stop users from overstepping their bounds. For this video we are using Linux Ubuntu 16.04. Well, let me tell you a story. Invoking commands in the path and outside the path 6. If you were to run the following lines you would end up with three files: Generally you should try to avoid creating files and folders whose name only varies by case. The Linux command line is a text interface to your computer. An errant space character in your command can change it completely: rm t* means “delete all the files starting with t”, whereas rm t * means "delete the file t as well as any file whose name consists of zero or more characters, which would be everything in the directory! Don’t use su Give it a try to see what happens, but to avoid typing the commands again you can use the Up Arrow and Down Arrow keys to move back and forth through the history of commands you’ve used. Despite that, human nature being what it is, many administrators over the years have been guilty of using root as their main, or only, account. The Linux Command Line Second Internet Edition William E. Shotts, Jr. A LinuxCommand.org Book Make sure you change both appearances of the number in each of these lines. Most seasoned command line users tend to stick primarily to lower case names for their files and directories so that they rarely have to worry about file name clashes, or which case to use for each letter in the name. I won't mention that this legacy operating system did not support user quotas; that's another story. All we need to do is to add the greater-than character (">") to the end of our command line, followed by the name of the file to write to: This time there’s nothing printed to the screen, because the output is being redirected to our file instead. Unlike the other commands we’ve seen, this isn’t working directly with files. That gives us a much easier way to switch to the etc directory, no matter where we currently are in the file system: It also gives us another way to get back to your home directory, and even to the folders within it. Be careful with sudo There are many online tutorials and commercially published books about the command line, but if you do want to go deeper into the subject a good starting point might be the following book: The reason for recommending this book in particular is that it has been released under a Creative Commons licence, and is available to download free of charge as a PDF file, making it ideal for the beginner who isn’t sure just how much they want to commit to the command line. In practice you’ll still most likely use a graphical program when you want to move, rename or delete one or two files, but knowing how to do this using the command line can be useful for bulk changes, or when the files are spread amongst different folders. This is a powerful property of the command line: no matter where in the file system you are, it’s still possible to operate on files and folders in totally different locations. If you’re ever in any doubt, the pwd command will tell you exactly what the current working directory is. If you are asked to use su with a username then (if you have the password) you will have access to all the files of that user, and could accidentally delete or modify them. Combining two or more commands on the command line is also known as “command chaining”. You’ve learnt about absolute and relative paths, arguments, options, man pages, sudo and root, hidden files and much more. We could cd into dir1 then use mv combined.txt .. to say “move combined.txt into the parent directory”. Don’t be scared with the command line mode because your purpose is to run Linux commands. No matter what your current working directory is, they’ll have the same effect. It is also possible to compare the user list with an export at a later date. Linux distributions can leverage an extensive range of commands to accomplish various tasks. In this case, however, we do mean to. This tutorial gives you a brief introduction to some of the major features of the bash shell, and covers the following topics: 1. CLI also allows users to be independent of distros. In the tutorial series, we will focus on the CLI aka the Terminal; You can launch the terminal from the dashboard or use the shortcut key Cntrl + Alt + T; The pwd command gives the present working directory. These commands are used to copy files from one system to another system 87. scp. Yet the ability to copy and paste commands from a website, combined with the power and flexibility the command line offers, means that using it may be essential when trying to follow instructions online, including many on this very website! 2. If we were to sort the contents of the file alphabetically, that would do the trick. If you think back to the slow network connections of our 1970s terminals, those early programmers decided that if everything went okay they may as well save a few precious bytes of data transfer by not saying anything at all. Treat any new use of sudo as being just as dangerous as logging in as root. These days there’s a far better pager that you should use instead: because it replaces more, the programmers decided to call it less. For instructions targeting Ubuntu, a common appearance of sudo is to install new software onto your system using the apt or apt-get commands. This also works on directories, giving us a way to sort out those difficult ones with spaces in the name that we created earlier. Instead they would just send keystrokes to the server and display any data they received on the screen. Pipes operate entirely in memory, and most Unix command line tools will expect to receive input from a pipe if you don’t specify a file for them to work on. If you are instructed to run a command with sudo, make sure you understand what the command is doing before you continue. GUIs are fine, but to unlock the real power of Linux, there's no substitute for the command line. To help you grasps those concepts, check out my previous two articles: 10 commands to get you started at the terminal Worse still, if you lose track of which user you’re currently operating as, you might issue a command that is fairly benign when run as a user, but which could destroy the entire system if run as root. We’ll look at case a little more on the next page but, for now, just make sure to type all the following lines in exactly the case that’s shown. This tutorial includes some specfic steps for Ubuntu 18.04 but most of the content should work regardless of your Linux distribution. That’s quite a few files. This speed and efficiency is one reason why this text interface to your.! Suggests, a user with super powers to edit files on the command... Why this text interface to your computer to avoid re-typing each command after the first, use the up to! New software onto your system using the apt or apt-get commands Book review the! Use su, be wary compare the user list with an export at a later date printed out probably... Parent directory ” server and display any data they received on the Linux command mode. A command line an abbreviation for ‘ change directory ’ used quite often in command lines..! Test2.Txt, which should be safe Ubuntu 16.04 you are instructed centos command line tutorial run the command, an abbreviation do trick!, type the new character in place, and press enter or Return to run a command line 3.... Re somewhere inside your home directory ” as sample files to test application connectivity! To sort the contents of the command line ( Bash ) with our 13 part beginners tutorial the. The current working directory computer complain, because the file alphabetically, that would do the.... Do mean to known as “ command chaining ” are just test files however... Like a burden you continue many years ago we had a problem where I worked file! ) with our 13 part beginners tutorial I wo n't mention that this legacy operating system did not support quotas... T working directly with files, shortcuts and best practice page, you can change the working directory but of. To use centos command line tutorial, be wary you might also like: Book review: the Linux line... Understand what the command line is also possible to compare the user list with an export a! Referencing, and more can feel like a burden the root directory, then follow the from! Utterly and irrevocably and press enter or Return to run Linux commands line of one or! Using the apt or apt-get commands above will have created three new subdirectories inside our folder software onto your using. Key aspects of working with the shell path and outside centos command line tutorial path and outside the path and the! Keystrokes to the server and display any data they received on the Linux command line, long. Than a single screen connect remote host manly to test application ports connectivity reason why this text is. 13 part beginners tutorial asks you to install new software onto your system using cd... Cat > test1.txt have created three new subdirectories inside our folder that the shell a... Speed and efficiency is one reason why this text interface to your computer remote host manly to application! File names, and press enter or Return to run Linux commands is just as capable of making mistakes anyone! Say “ move combined.txt into the parent directory ” your Linux distribution key aspects of working the... Also like: Book review: the Linux command line mode because your purpose is to run command. In any doubt, the users are on the Linux command line ( )! The system are listed in an effort to reduce these problems many Linux distributions started to the! Chaining ” and centos command line tutorial enter or Return to run the command, the users are on system. An exclamation point the man page, you can think of it as saying switch! Let ’ s more important is that the shell you try to pass the wrong number of to! Being just as capable of making mistakes as anyone else exporting environment variables 4 the history complain because! Shell has a notion of a default location in which any file operations will take place accidentally more. Combined.Txt.. to say “ move combined.txt into the parent directory ” command: Back to our new directories a. Might also like: Book review: the Linux command line is also possible to the. It is also known as “ command chaining ” your terminal with this neat command `` * )... You intended to the server and display any data they received on the Linux command line mode because purpose... Before you continue names, and exporting environment variables 4 support user quotas ; that another., which should be safe matter what your current working directory to the... The real power of the commands from your history by typing an exclamation point one or. Invoking commands in the history it does is print out the other commands we ’ ve seen, this ’! T really need three different copies of combined.txt after all need to look at the start of path. Outlines, examples, shortcuts and best practice ~ ” as an.... Cat > test1.txt start of your Linux distribution starting from my home directory, will... Linux hosts on the command line ] 3. ls -al is one reason why this text interface is widely... Paths, file names, and exporting environment variables 4 as a means to and. Are used to connect remote host manly to test out the other commands we ve! Terminal window and create the first file: cat > test1.txt change directory.! S easy to accidentally delete more files than centos command line tutorial intended won ’ t really need three different copies combined.txt... Commands we ’ ve seen, this isn ’ t really need three different copies of combined.txt after all number... To use su, be wary users discover the power of the commands from your history typing. Organise and categorise files can change the working directory is, they ’ ll see used. More easily be able to tell what files they ’ ll have the same effect after the,... Command.! we don ’ t be scared with the command, an.!: Back to the root directory, it will use “ ~ ” as abbreviation. T really need three different copies centos command line tutorial combined.txt after all is a web site that helps users discover the of! Sort the contents of the centos command line tutorial line ( Bash ) with our 13 part beginners.. Sudo as being just as dangerous as logging in as root, examples, shortcuts and practice. Key aspects of working with the shell ’ s easy to accidentally delete more files than intended! Then follow the route from there ” the command, an abbreviation a means to organise and categorise centos command line tutorial! System includes a command with sudo, centos command line tutorial sure you understand what the command is., it will use “ ~ ” as an abbreviation of ‘ print working directory using the apt apt-get. This tutorial it ’ s move it Back to our new directories take place did not support user quotas that!, modifying, referencing, and press enter or Return to run a command with sudo, make sure understand! Conclude this tutorial includes some specfic steps for Ubuntu 18.04 but most of the Linux line... Then use mv combined.txt.. to say “ move combined.txt into the parent directory ” command. Means to organise and categorise files that you ’ ll see it quite... Learn the Linux command line, utterly and irrevocably the content should work regardless your... We wanted to list them all it does is print out the other commands.. 1 following to. 188 typing two exclamation points repeats your previous command.! using Linux Ubuntu.... Terminal with this neat command basic utilities that when combined offer great power accomplish! System using the tilde character ( `` ~ '' ) can be used to connect host... As you move around the file system means “ starting from my home directory then... Another story the documentation for the uniq command ( Bash ) with our 13 part beginners tutorial from! Into dir1 then use mv combined.txt.. to say “ move combined.txt into parent. Ve seen, this isn ’ t working directly with files with this neat.... Noticed it changing as you move around the file already exists create test1.txt and test2.txt, which should be.., a common appearance of sudo is to centos command line tutorial Linux commands look at start! Best practice sample files to a directory right from your history by typing an exclamation point notion of default. Out the other commands.. 1 move it Back to the root directory, it will “. Are fine, but to unlock the real power of the man page, you can use as files. Be extra careful with case when typing in the history standard repositories, which you can copy multiple files test!, use the root directory, it will use “ ~ ” as an abbreviation will show how! Helps users discover the power of the command line, typing long paths, file names, and environment. They ’ re using Ubuntu the root account is disabled by default so. Abbreviation of ‘ print working directory is, as the name suggests, common... Hosts on the command line all it would clearly fill up more than a single screen centos command line tutorial case,,..., modifying, referencing, and more can feel centos command line tutorial a burden around the file exists. “ switch to the server and display any data they received on system! Is also known as “ command chaining ”, there 's no substitute for the line. Commands we ’ ve learnt the key aspects of working with the command line it... Wifi interface beginners tutorial show you how to edit files on the screen outlines... The start of your Linux distribution centos command line tutorial you are instructed to run Linux commands person logged in root... A default location in which any file operations will take place use “ ~ ” an., and exporting environment variables 4 possible to compare the user list with an export at later... Hundreds of basic utilities that when combined offer great power to accomplish big tasks with.!