Linux / Ubuntu CLI(Command Line Interface) for beginners
Tags: linux, ubuntu, cli, commandlineinterface
Published: 2021-11-24 14:59:51

#What is Ubuntu and Linux?
To start with, I had the same question myself because I had no idea so I am adding this link.
[What is difference between Ubuntu and Linux?](https://www.quora.com/What-is-difference-between-Ubuntu-and-Linux)
Linux as an operating system (although it is actually a kernel but we don't need to get into that

## [Linux](https://www.linux.com/what-is-linux/)
Just like Windows, iOS, and Mac OS, Linux is an operating system. In fact, one of the most popular platforms on the planet, Android, is powered by the Linux operating system. An operating system is software that manages all of the hardware resources associated with your desktop or laptop. To put it simply, the operating system manages the communication between your software and your hardware. Without the operating system (OS), the software wouldn't function.
<strong>Kernel</strong> – This is the one piece of the whole that is actually called Linux. The kernel is the core of the system and manages the CPU, memory, and peripheral devices. The <u>kernel is the lowest level of the OS.</u>

#[Ubuntu](https://ubuntu.com/tutorials/command-line-for-beginners#1-overview)
Ubuntu is a complete Linux operating system, freely available with both community and professional support.

Ubuntu is a Linux distribution.
Distribution is an operating system made from a software collection that is based upon the Linux kernel.
So, Ubuntu is Operating system built on Linux.(if you click their names, you can go to their website and find out more about them)


At the class, we practiced using command line using [goorm ide](https://www.goorm.io/)!
goorm is cloud-based ide(integrated development environment) and they use Amazon EC2(Amazon Elastic Compute Cloud)for their service.


#Command Lines for beginners

<code><strong>mkdir</strong></code> make directory
<code><strong>mkdir -p /one/two/three</strong></code> make directory three inside two and one inside two
<code><strong>mkdir one two three</strong></code> make directory one, two, three
<code><strong>cd</strong></code> change directory
*You can change the working directory using the cd command
<code><strong>cd nameofdirectory</strong></code> go to the directory typed after cd
<code><strong>cd ..</strong></code> go up to the parent directory
<code><strong>cd /</strong></code> using “/” at the start of your path means “starting from the root directory” so it goes to root directory
<code><strong>cd ~</strong></code> character (”~”) at the start of your path similarly means “starting from my home directory”.
<code><strong>pwd</strong></code> print working directory(use this when you don't know where you are at currently, it will show you your working directory)
<code><strong>ls</strong></code> print file list of current directory
<code><strong>ls -a</strong></code> all, print all of the files including hidden files of current directory
<code><strong>ls -al</strong></code> it's like mix of <code><strong>ls -a</strong></code> and <code><strong>ls -l</strong></code>. It prints more detailed data including file permission, size, etc. Also <code><strong>ll</strong></code> is the same as <code><strong>ls -al</strong></code>
<code><strong>ls *.txt</strong></code> print every files that file extension is .txt
<code><strong>alias</strong></code> is a command making shortcut.
<strong><code>alias ls="ls -a"</strong></code> this makes <strong><code>ls</strong></code> as a shortcut of <code><strong>ls -a</strong></code>
You can undo this by <strong>unalias ls</strong></code> 
<code><strong>touch filename</strong></code> create file named filename (i.g: <code><strong>touch test.txt</strong></code> will make txt file named test)
<code><strong>touch test1.txt test2.txt</strong></code> create test1.txt and test2.txt
<code><strong>touch test1.txt;test2.txt</strong>
</code> create test1.txt and test2.txt (You can put two or more commands on the same line separated by the semicolon. <code><strong>;</strong></code> means - if the previous command fails, still execute the next command. <code><strong>&&</strong></code> means - execute the next command only when the previous command was executed successfully
<code><strong>&</strong></code> makes the command run in the background
<code><strong>mkdir one;cd one</strong></code> make directory one and go to directory called one (it executes at once)
<code><strong>echo "This is a test"</strong></code> print "This is a test"
<code><strong>echo "hello world" > hello.txt</strong></code> save "hello world" in hello.txt (So, this saves the echo result inside hello.txt that gets created by this command)
<code><strong>cat hello.txt</strong></code> it prints "hello world"
```
$echo "nice to meet you" > greeting.txt
$cat greeting.txt
nice to meet you

$echo "i like blue" > one.txt
$echo "i like black" > two.txt

$cat one.txt two.txt
i like blue
i like black
```
<code><strong>cat music.txt > song.txt</strong></code> 
save content of music.txt to song.txt and it prints the content of song.txt
If you use <code><strong>>></strong></code> instead of <code><strong>></strong></code>, it will add the new content at the end of existent content of the file  not replacing the content
<code><strong>mv</strong></code> move
<code><strong>mv test1.txt dir1</strong></code> move test1.txt file to a directory named dir1
<code><strong>mv test.txt new-test.txt</strong></code> move test.txt file to new-test.txt and test.txt disappears.(It's like changing file name)
<code><strong>cp</strong></code> copy
<code><strong>cp one.txt two.txt</strong></code> create another copy of the file, in our working directory but with a different name(two.txt)
<code><strong>cp test.txt | grep "JavaScript"</strong></code> opens text.txt and find text of "JavaScript"
<code><strong>cp hello.txt dirname</strong></code>
copy hello.txt in the directory named dirname
<code><strong>find . -name '*.txt'</strong></code> find every file that file extension is .txt and print where it is.
<code><strong>rm</strong></code> remove
<code><strong>rm filename</strong></code> remove file named filename
<code><strong>rm dirname</strong></code>remove directory named dirname(but it won't work if there's file inside dirname)
<code><strong>rm -r dirname</strong></code>this will delete directory named dirname even if there are files inside
<code><strong>-r</strong></code> means remove directories and their contents recursively.