0% found this document useful (0 votes)
7 views8 pages

Command Line Interface - Notes (1)

The document provides essential notes for a command line interface event organized by The Learning Olympics, including sample tasks and commands to practice. Participants are instructed to create directories, write code in multiple programming languages, and manage files using various command line commands. Caution is advised against executing commands on local machines due to potential data loss, and a link to an online terminal for practice is provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Command Line Interface - Notes (1)

The document provides essential notes for a command line interface event organized by The Learning Olympics, including sample tasks and commands to practice. Participants are instructed to create directories, write code in multiple programming languages, and manage files using various command line commands. Caution is advised against executing commands on local machines due to potential data loss, and a link to an online terminal for practice is provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

THE LEARNING OLYPICS

EVENT -1
COMMAND LINE INTERFACE
Hey everyone, here are the basic notes that are prepared by The Learning
Olympics team.
These notes will give you insight on the commands you need to learn that
will help you accomplish the event’s task and quiz.
Sample questions:
1. Create five directories such that dir1/dir2/dir3/dir4/dir5/. Note that
the dir5 is present within dir4 which in turn present in dir3 and so on
till dir1. Create three files (name.txt, email.txt, role.txt) outside of
dir1 and copy each of these files into all the directories. (dir1 will
contain name.txt, email.txt, role.txt and dir2 will contain name.txt,
email.txt, role.txt and dir3 will contain name.txt, email.txt, role.txt
and so on). Fill in the content for name.txt, email.txt, role.txt of you
choice.
*Try to keep things simple and try to reduce the number of steps.
Instead of copying one file at a time to one directory. Try to find an
easier way out.

Result should look like this:


2. Write a C++ code in the command line interface terminal, where you
print “hello world”. Similarly write a code in python and Nodejs,
remember it is to be written in the command line terminal itself.
Make sure to copy the output into a pdf file, again do this using the
terminal alone.
*You can write the code using echo command then compile that file.

3. Copy all the content of and place them into one pdf file named as
‘final.pdf’
The result should look like this:

The terminal for the event is: https://labs.play-with-docker.com/#


➢ Go to the site and register (you can use your personal email)
➢ Login with your new credentials
➢ It might ask you to authorize ‘docker play’ to use your account click
ok.
➢ Then click on start.

➢ Click on Add new instance.

CAUTION!

The commands listed here are powerful tools that can alter or delete
files, directories, and configurations on your system. Practice these
commands solely on a safe online terminal or a designated test
environment (Docker Play).

AVOID USING COMMANDS ON YOUR LOCAL MACHINE FOR PRACTICE. The


Command Line Interface (CLI) can execute actions that may not be
reversible and could potentially cause data loss or system instability.

Always exercise caution and ensure you understand the implications of


each command before executing it. If you're uncertain about a command
or its consequences, seek guidance or practice in a controlled
environment to prevent unintended outcomes.
Here are the basic commands you should be familiar with. You can use the
link and practice these commands and the sample questions in the online
terminal (Docker Play)
KEYWORD CONTEXT SYNTAX EXAMPLES
ECHO Print text to terminal echo [text] > [filename]echo 'Hello, World!' >
or file greeting.txt
echo '12345' >
numbers.txt
echo 'This is a sample
text' > sample.txt
PYTHON Execute Python script python [filename] > python script1.py >
[output_filename] output1.txt
python calculate.py >
result.txt
python
data_processing.py >
processed_data.txt
G++ Compile C++ code into g++ -o g++ -o program1
executable file [output_filename] source1.cpp
[source_filename] g++ -o calculator
calculator.cpp
g++ -o data_analysis
data_analysis.cpp
./OUTPUT Run an executable file ./[executable_filename] ./program1 >
program_output.txt
./calculator >
calculation_results.txt
./data_analysis >
analysis_output.txt
SUDO Execute command sudo [command] sudo apt-get update
with superuser sudo systemctl
privileges restart nginx
sudo useradd -m
newuser
APK Alpine Linux package sudo apk [add/install sudo apk add curl
manager command] [package] sudo apk add python3
There are different sudo apk add gcc
package managers.
NODE Execute Node.js script node [filename] > node app.js >
[output_filename] app_output.txt
node server.js >
server_output.txt
node
data_processing.js >
processed_data.txt
CAT Concatenate and cat [file1] [file2] ... > cat file1.txt file2.txt >
display file content [output_filename] combined_files.txt
cat log1.txt log2.txt >
merged_logs.txt
cat header.txt
content.txt >
full_document.txt

Keyword DESCRIPTION SYNTAX EXAMPLE


CD [DIRECTORY] Change current cd [directory] cd Documents
directory.
pwd Print current pwd pwd
working
directory.
ls List files and ls ls
directories.
ls -l List in long ls -l ls -l
format.
ls -a List all, ls -a ls -a
including
hidden.
cd ~ Navigate to the cd ~ cd ~
home directory.
cd .. Move up one cd .. cd ..
level.
man Display manual man [command] man ls
page.
touch [file] Create an touch [file] touch newfile.txt
empty file.
cp [source] Copy. cp [source] cp file1.txt backup/
[destination] [destination]
mv [source] Move/rename. mv [source] mv file1.txt documents/
[destination] [destination]
rm [file] Remove file. rm [file] rm oldfile.txt
rm -rf [directory] Force remove. rm -rf [directory] rm -rf
unwanted_directory/
rm -r [directory] Remove rm -r [directory] rm -r empty_directory/
directory.
(caution)
mkdir [directory] Create mkdir [directory] mkdir new_directory
directory.
rmdir [directory] Remove empty rmdir [directory] rmdir empty_directory/
directory.
rm -r [directory] Remove rm -r [directory] rm -r
directory. directory_to_remove/
(caution)
du [options] Show disk du [options] du -h Documents/
[directory/file] usage. [directory/file]
tree [directory] Display tree [directory] tree project/
hierarchical
structure.
cat [file] Display file cat [file] cat textfile.txt
contents.
less [file] View file screen less [file] less longfile.txt
by screen.
head [file] Display head [file] head logfile.txt
beginning of
file.
tail [file] Display end of tail [file] tail log.txt
file.
grep [pattern] [file] Search pattern. grep [pattern] [file] grep "error" log.txt

sed [options] Stream editor. sed [options] sed 's/old/new/g' file.txt


[script] [file] [script] [file]
chmod Change chmod chmod 755 script.sh
[permissions] [file] permissions. [permissions] [file]

chown Change chown chown user:group


[user]:[group] [file] ownership. [user]:[group] [file] myfile.txt

whoami Display current whoami whoami


username.
who Show logged-in who who
users.
users List all users. users users
groups [user] List user groups [user] groups username
groups.
ps [options] List processes. ps [options] ps aux
top Display system top top
stats.
kill [PID] Terminate kill [PID] kill 1234
process.
tar [options] Create/compre tar [options] tar -cvf archive.tar
[archive_name] ss tar archives. [archive_name] directory/
[files/directories] [files/directories]

zip [options] Create zip [options] zip -r archive.zip


[zipfile] compressed [zipfile] directory/
[files/directories] zip. [files/directories]

unzip [options] Extract from unzip [options] unzip archive.zip -d


[zipfile] -d zip. [zipfile] -d extracted/
[destination] [destination]
ping [host] Send echo ping [host] ping google.com
requests.
ifconfig [interface] Display/configu ifconfig [interface] ifconfig eth0
[options] re interfaces. [options]

ssh [user]@[host] Connect via ssh [user]@[host] ssh user@hostname


SSH.
uname -a Display system uname -a uname -a
info.
df [options] Display disk df [options] df -h
[file/system] space. [file/system]
free [options] Display free [options] free -m
memory usage.
uptime Show system uptime uptime
uptime.
find [dir] -name Search by find [dir] -name find /home/user -name
[file] name. [file] *.txt
locate [file] Quickly locate. locate [file] locate importantfile.txt
nano [file] or vi Text editors. nano [file] or vi nano document.txt
[file] [file]
cat [file] > [newfile] Redirect. cat [file] > [newfile] cat log.txt >
backup_log.txt
more [file] or less View page by more [file] or less more longfile.txt
[file] page. [file]
scp [file] Secure copy. scp [file] scp file.txt
[user]@[host]:[dest [user]@[host]:[dest user@remote:/path/to/
ination] ination] destination/
rsync [options] Synchronize. rsync [options] rsync -avh source/
[source] [source] destination/
[destination] [destination]
gzip [file] or Compress/deco gzip [file] or gzip document.txt
gunzip [file.gz] mpress (gzip). gunzip [file.gz]
bzip2 [file] or Compress/deco bzip2 [file] or bzip2 data.txt
bunzip2 [file.bz2] mpress (bzip2). bunzip2 [file.bz2]

export Set export export


[variable]=[value] environment [variable]=[value] PATH=$PATH:/new/dire
variable. ctory
echo $[variable] Print variable echo $[variable] echo $HOME
value.
history List past history history
commands.
!n Execute the nth !n !15
command.
`command1 command2` Pipe output. `command1
command > [file] Redirect command > [file] echo "Hello" >
output. greeting.txt
command >> [file] Append output. command >> [file] echo "World" >>
greeting.txt
command < [file] Use file as command < [file] `cat input.txt
input.
grep [regex] [file] Search with grep [regex] [file] grep "^error" logfile.txt
regex.
sed Substitute with sed sed s/old/new/g file.txt
s/[pattern]/[replac regex. s/[pattern]/[replac
ement]/g [file] ement]/g [file]

You might also like