Welcome to Alfresco University's Linux Command Line Primer!
Please read this entire page as it includes information related to navigating this module as well as other information.
This module was cerated as a way to assist those not versed in Linux as a short 'how to' pertaining to basic concepts of the Linux Operating System and some of the basic commands available and how to use them.
This is important as the lab exercises in Alfresco use an Ubuntu Linux based system where you, the student, will perform your labs.
Navigating this module:
This module consists of 7 separate sections, with each section containing a number of video demos, audio narration, command examples and text.
When you first login to the module you will be in the home page. The home page contains all the various sections of the module.
When you click on the 'START" in a section you are presented with the section menu.
This module also contains a downloadable PDF 'Linux Cheat Sheet', containing some of the basic commands that were covered.
The shell is a program that takes commands from the keyboard and gives them to the operating system to perform or execute. On most Linux systems, you will hear the term 'bash', but this doesn't mean to beat up your computer. Although we have all wanted to do that from time to time.
Instead 'bash,' or 'Bourne Again Shell,' is an enhanced version of the original Unix Shell program. Bash usually acts as the shell in Linux distributions.
|A linux 'Shell'|
In your assigned Alfresco University virtual machine (or "VM"), you can open a terminal window or several by clicking the link on the desktop.
Once the terminal is open, you can begin issuing commands by simply typing into it using your keyboard.
To close a terminal window, you can use the ‘exit’ command.
If there are processes running in the background when you use this command, the shell will remind you that they are running. In these cases, entering ‘exit’ again will shut down any running processes and close the shell.
|Command example: Using the 'exit' command|
You can think of the structure of your computer as a “directory” of different files and folders. If you’re used to using a user interface on your computer to navigate, such as Finder on Mac or the Menu on Windows, this may seem a little confusing. In short, when you see a folder in your UI, you are looking at what programmers refer to as a “directory.” Directories can hold individual files-- such as an HTML or Microsoft Word file-- or other directories, which can then themselves hold files and even further nested directories.
In Linux, you can often still use a UI to navigate your computer’s files and directories, but there is an easier way: using the shell. There are several different commands you can use, and each of them accomplishes something different. As we go through some of the basic commands, we’ll show you visually what happens when each command is used, so that you can begin to understand what is actually happening with your files and directories.
|Click the play button on the video below to learn more about the Linux directory structure.|
To determine what directory you are currently working in you can use the ‘pwd’ command. PWD stands for “print working directory,” meaning that you want the terminal or shell to print out the name of the directory you’re currently working in.
‘pwd’ displays or prints to the screen the full pathname to the current working directory.
|Click the play button on the video below to learn more about the 'pwd' command|
|Command Example: Using the 'pwd' command|
CD, or “change directory,” allows you to change your current working directory to a different one.
When you first open a terminal, you are in your “home” directory. Directories are separated by a forward slash. For example: "home/alfresco."
To change to a different directory, you enter the full path, relative to your current directory, that you want to navigate to. If we wanted to navigate to the directory "/home/alfresco/logs", we would enter the command:
|Click the play button on the video below to learn more about the 'cd' command|
One important piece of information you should note is that “CD” only works as you’re “drilling down” into a directory.
For example, if you type “cd home/alfresco,” you are going into the directory alfresco, which is located inside home. If you try to CD into a directory that isn’t located in your current one, your terminal will throw an error. If you’d like to navigate “up” a level, you need to enter two periods, followed by a slash. This indicates that you are moving up a level in the directory, which will allow you to access any files or directories at that level. Remember, if you need to know which directory you are currently working in, you can enter PWD to check the name of your current directory.
|Command example: Using the 'cd' command|
One key feature available in many shells in Linux is the autocomplete feature.
This feature is available on your Ubuntu virtual machine by simply using the ‘tab’ key on your keyboard.
When you need to navigate directories and are unsure of the exact path, you can enter your command and a few characters of the directory you are wanting to navigate to, and then press the ‘tab’ key.
This will finish your character input, or present you with several options based upon what you have initially entered.
|Command example: using the 'tab' key to autocomplete|
In Linux, you will sometimes want to check what files and directories are located in your current directory. This can be especially important and useful if you have many different files, or even if you just forget where specific files and directories are located on your computer. You can check this easily in your terminal or shell by typing the command “LS,” which is Linux shorthand for “list all the contents in this directory.”
For example, if you’re in your “home” directory, you can type “LS” to see what other directories you can access, or which files are in that directory.
|Click the play button on the video below to learn more about the 'ls' command|
To create a new directory, you may enter the “MKDIR” command in your Linux shell. MKDIR is shorthand for “make directory,” and when you enter this command, you’ll need to follow it with whichever name you want to give to your new directory. For example, here in your shell, you can see we type “mkdir newSample.” If we list the contents, we now see our newSample directory listed in our current folder.
You can create new directories in any location on your computer, as long as you know the correct pathname. So, if you’re in your “home” directory, you can enter “mkdir home/alfresco/newSample2.” If you then CD into your “alfresco” directory, you should see your “newSample2” directory listed.
|Click the play button on the video below to learn more about the 'mkdir' command|
|Command example: using the 'mkdir' command|
If you have a text file or a log that you would like to review within your terminal, you can enter the command “less” to display it. Many Linux users may choose to use the “more” command for this as well, but the primary difference (and benefit) of less is that you can scroll both forward and backward within a file-- whereas with “more,” you can only go forward.
When you enter the “less” command, you need to also enter the filename, such as “less sample.txt.” Hitting the space bar allows you to move to the next page of the file, while hitting the “Enter” key allows you to scroll to the next line.
To review a particular file’s type, you may simply enter “file [filename].” The terminal should then list the correct type of the file. For example, if you enter “file sample.py”, the terminal will show that it is a Python file.
|Click the play button on the video below to learn more about the 'file' command|
The rm command removes files or directories, and often with an optional parameter directories.
To use this command, you enter ‘rm’ followed by the filename you wish to remove.
The data itself is not destroyed, but after being unlinked, it becomes inaccessible.
It’s important to remove your files wisely, as the effects of an rm operation cannot be undone.
As with most Linux commands there are a number of optional parameters that can be applied, such as dash lower case i.
This parameter will prompt the user before removing each file.
The rm command can also remove directories including directories that are not empty.
To remove directories, you will need to use the dash lower case r parameter.
The dash r parameter tells the system to delete the named directory, and sub directories as well as files in these directories from the system.
Be careful when using this command and be sure you are in the correct directory prior to issuing it, as this command cannot be undone.
|Click the play button on the video below to learn more about the 'rm' command|
The command line provides numerous ways to create new files.
For example, you can create a file using the ‘touch’ command.
To use this command, you simply enter the command and the filename you wish to create, for example ‘touch mynewfile.’ This will create a empty file, which you can then open in a file editor or further utilize with your shell commands.
The other option would be to specify the application with which you want to create a new file.
|Click the play button on the video below to learn more about the 'touch' command|
Ubuntu by default comes pre-installed with a graphical editor called gedit. To create a new file using gedit, you would type ‘gedit’ and then the filename.
For example, you might enter: ‘gedit mynewfile.’
This will create a new file and open it in gedit for editing.
The cp command is used when you need to copy, or copy files to a different location. This command can also be used to copy, and then rename the copied files. To use this command, you enter the command ‘cp’ followed by the directory where the file currently exists and the filename itself, and then, finally followed by the directory where you wish to move the file to.
For example, you may enter: ‘cp path/to/filename path/to/move/to/filename’
You can also specify a new name if you wish to change the filename to something else.
For example ‘cp path/to/filename path/to/move/to/newfilename’
There are a number of optional parameters available with this command, such as ‘-u’ or ‘update’. The ‘update’ option only copies the file if the file being copied is newer then the file in the destination directory or there is no file in the destination directory.
You can also move files from one directory to another using the mv command.
The syntax follows the same procedures as the copy command but instead of making a copy of the file it will just move the file to a new location or you could also just rename a file.
Many of the same parameters that are available in the cp command are available in mv.
When accessing the shell you are granted permissions based upon the specific user within the system.
Why do I need to change permissions or modify user access?
There are times when these permissions are insufficient for one reason or another. For example you might need to install a program or run a script that requires administrative permissions.
Okay, no problem. How do I go about doing this?
There are two ways or commands, that allow you to be granted administrative permissions.
One of these is 'su'. When using this command you are effectivly granted root permissions. This can set a dangerous precedent as it effectively allows you full permissions over the entire system, and if you are not careful you can cause a lot of damage including making the system inoperable.
As a matter of fact, some distributions including the ones we will be using, 'Ubuntu', have the root user account disabled.
The second option is to use 'sudo', this allows you to temporarily be granted administrative permissions.
To use 'sudo,' you preface your commands with it instead of 'su.'
sudo mkdir 'mydirectory'
|Command example: using the 'sudo' command|
In Linux, there are rules for each file that defines who can access the file and how they can access it. These rules are called file permissions or file modes.
The command chmod stands for 'change mode' which is used to define the way a file can be accessed.
The chmod consists of the following form:
‘Chmod options permissions filename’
For example: ‘Chmod +x filename’
The '+x' option says to add execute permissions to the filename that is being specified. This is one of many ways you can build and use the ‘chmod’ command.
When content is created or added to a Linux system, by default the user that performed the action is the owner. The owner of a file is also a member of a specific group which shares his or her permissions on the file. The ‘chown’ command is used to change the owner and group of files, directories and links within Linux.
|Command example: using the 'chown' command|
The ‘ps’ command is used to get a snapshot of all the current processes that are running on the system.
This command is useful for determining whether a process is already running, or whether is has been stopped.
There are numerous parameters that can be used to limit or even to sort the data that is returned.
The ‘kill’ command can be used to send a signal to stop, or “kill” a running process, script, server, or program.
This command can be used in conjunction with the ps command to determine the process id or ‘PID.’It is very powerful and is useful when you need to stop a process prior to performing some other action. However, you need to use the ‘kill’ command carefully, as the name implies you can terminate any running process, and if misused, this can cause a system malfunction.
This command lists all of the available built-in shell commands.
You can also include a specific shell command to get more detailed help by adding its name as a parameter.
The ‘which’ command returns the pathnames of the files, or links, which would be executed in the current environment once a filename been given as a command.
It effectively searches the paths using the PATH environment variable for executable files that match the name specified.
The ‘man’ command or sometimes referred to as ‘man pages,’ allows you to reference the system’s reference manuals.
This is useful to get additional detailed help for a particular command including its optional parameters and use case examples.
To use man pages you specify the command and the reference material you want to view.
Specifying the man page for the rm command:
Specifying the man page for the man command
The jps command is used for listing the java virtual machines (or "JVM") that are running on the system. This is useful for determining if a specific jvm process is running. This will list only the jvm’s that are running and no other processes.
This command can be used to determine the process id or pid of a process if you need to shut it down.