Linux is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. System commands are a computer user’s instruction (not part of a program) that calls for action by the computer’s executive program. Most of the “commands” that we use on the Linux command line are in fact programs (which are stored as files) located typically in the /bin or /usr/bin directories. Take the cp command for instance. You can use the “which” command to determine where the cp program is located.
Basic commands and Paths
What is the date?
1
$ date
Let’s print something
1
$echo"Hello World"
Paths: what are they
1
$echo$PATH
Files and Paths
1
$which python
Get Help
1
$ man echo
Get short help
1
$ whatis echo
Navigating Paths
Where am I in the structure?
1
$pwd
What’s in here?
1
$ ls
OR prettier, what’s in here?
1
$ tree
How to change to another directory?
1
$cd directory_name
How do I move up the directory structure?
1
$cd ..
How do I move to my home directory?
1
$cd ~
Files Creaing and Moving
Create a file
1
$ touch file_name
Is the file there?
1
$ ls -l file_name
What’s in the file
1
$ cat file_name
What type of file is this
1
$ file file_name
Rename, Move this file to another directory
1
$ mv original_file final_file
Find the file
1
$ ls -l final_file
Copy the file (make a second copy)
1
$ cp file_name new_file_name
Cobble files (DO NOT Try this)
1
$ cp file_name existing_file_name
Combine multiple files into another
1
$ cat file1 file2
See the beginning of a file
1
$ head file
See the end of a file
1
$ tail file
Pause between each pageful of file
1
$ less file
Same thing (older)
1
$ more file
Directories
Create a directory
1
$ mkdir dir1
List the directory
1
$ ls -al dir1
Dot, dot dot, dash, and tilde
1
$cd . ; cd .. ; cd - ; cd ~
Rename/Move a directory
1
$ mv dir1 dir2
Nest directories (be careful)
1
$ mv dir2 dir3/
Removing files/directories
Remove a file
1
$ rm file1
Remove an empty directory
1
$ rmdir dir1
Remove a directory and files in it (CAREFUL)
1
$ rm -r dir1
Remove a link. Careful with symlinks
1
$ rm linkname
Try to remove a file you don’t have permissions to
1
$ rm linkname
Links
Create a hard link to a file. This creates another path to the file contents.
1
$ ln target linkname
Create a symbolic link to a file or directory. This creates a link to the existing path, and not the file contents.
1
$ ln -s target linkname
Ownership and Permissions
Look at permissions and owners
1
$ ls -l file
Change owners, groups
1
$ chown ambrish file1
Change file permissions of file1
1
$ chmod a+x file1
Make readonly for g and o
1
$ chmod go-r file1
Or something more precise
1
$ chmod u=rx,g=rwx,o=r file1
Compiling a C file
The original file can be checked
1
$ cat first.c
To compile we use the GNU C compiler gcc
1
$ gcc -o first first.c
This creates the file first, which you can see is executable
1
$ ls -l first*
Run the file
1
$ ./first
Processes
Look at processes running
1
$ ps -ef
Look at expensive processes
1
$ top
Same thing (Newer)
1
$ htop
Run something in the background (Get my prompt back)