0% found this document useful (0 votes)
15 views

Basic Linux Commands Study Guide

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Basic Linux Commands Study Guide

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Study Guide: Basic Linux Commands

Basic Linux commands are beneficial to developers when interacting with a Linux operating
system through the command line interface. They are used when working with files and
directories. Typically, they are easy to learn and apply, and provide developers with
additional commands for more advanced situations. If needed, these commands are also
easy to look up on your preferred search engine.

In this reading, you will review basic Linux commands with examples provided along the
way.

Managing files and directories


Many applications configure themselves by reading files. They are designed to read and
write files in specific directories. Because of this, developers need to understand how to
move and rename files, change their permissions, and do simple operations on their
contents. Here are some common commands:

mv
mv is used to move one or more files to a different directory, rename a file, or both at the
same time.

Note: Linux is case-sensitive, so mv can also be used to change the case of a filename.

Examples:

 mv myfile.txt dir1/ # This command moves a file to the directory.


 mv file1.txt file2.txt file3.txt dir1/ # This command moves multiple files.

cp
cp is used to copy one or more files.

Examples:

 cp file1.txt file2.txt # Copy file1.txt to file2.txt.


 cp file1.txt file2.txt file3.txt dir1/ # Copy multiple files to dir1.

chmod/chown/chgrp
chmod/chown/chgrp is used to make a file readable to everyone on the system before
moving it to a public directory.

Example:

 chmod +r file.html && mv file.html /var/www/html/index.html # Make file.html


readable and move to public directory.
Operating with the content of files
Every programmer will use files for something. Whether it’s for configuration, data, or input
and output, programmers work with files and need to know how to operate with their
contents.

cut
cut is a command that extracts fields from a data file.

Examples:

 cut -f1 -d",", addressbook.csv # Extract the first field from a CSV file.
 cut -c1-3,5-7,9-12 phones.txt # Extract specific characters from a phone number list.

sort
sort is a command that sorts the contents of a file.

Examples:

 sort names.txt # Sort inputs alphabetically.


 sort -r names.txt # Sort inputs in reverse alphabetical order.
 sort -n numbers.txt # Sort numbers numerically.

Combining multiple commands


Examples of combining multiple commands:

 ls -l | cut -w -f5,9 | sort -rn | head -10 # Display the 10 largest files in the current
directory.
 cut -f1-2 -d"," addressbook.csv | sort # Extract and sort first and last names from a CSV
file.

Additional commands

id
id is a command that prints information about the current user.

Example:

 $ id
 uid=3000(tradel) gid=3000(tradel)
groups=3000(tradel),0(root),100(users),545(builtin_users),999(docker)

free
free is a command that prints information about memory on the current system.
Example:

 free -h # Print memory information in human-readable units.

Key takeaways
Basic Linux commands assist developers in different types of tasks related to managing files
and directories and working with the content of each file. These commands allow
developers to work more efficiently and effectively.

You might also like