You can use the CLI to do simple or complex text manipulation. As developers, you will use an IDE like PyCharm or Visual Studio Code to do such tasks most of the time. However, it can be handy to do from the CLI sometimes. Many scripts used to compile and build software these CLI text-manipulation techniques.
Most CLI commands, including the ones you have already seen like ls
and pwd
have an output that is printed to the terminal. Some commands, like cp
, do NOT have an output printed to the screen.
Below you will see the special >
and >>
operators.
>
is the redirect operator. It takes the output from a command and writes it to a file you specify, e.g., echo "hello" > file.txt
. It will create the file if it does not exist, and will overwrite the file if it does exist!>>
is the append operator. It will create the file if it does not exist, and will append to the end of the file if it does exist!echo
- Display a line of textcat
- Concatenate and display file contentsmore
- View file contents one screen at a timeecho "Hello, CLI" > hello.txt
cat hello.txt
echo "Another line" >> hello.txt
cat hello.txt
seq 1 1 10000 >> numbers.txt # making a big file - no need to learn.
cat numbers.txt
more numbers.txt # Spacebar goes forward, b goes back, q to quit.
echo "Hello, CLI" > hello.txt
cat hello.txt
echo "Another line" >> hello.txt
cat hello.txt
1..10000 | Out-File numbers.txt # making a big file. Don't worry about learning this command.
cat numbers.txt
more numbers.txt # Spacebar goes forward, b goes back, q to quit.
echo
to create a text file with some content. Try echo "this is my first file" > myfile.txt
cat
will print all of the file’s contents to the screen all at once.echo
to append text to the file.more
to view the file content one screen at a time. Hit q
to exit.echo
?Move on to process management.