LINUX Activity 1: touch The touch command can be used to rapidly create one or more empty files. While the touch comman

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

LINUX Activity 1: touch The touch command can be used to rapidly create one or more empty files. While the touch comman

Post by answerhappygod »

LINUXActivity 1: touchThe touch command can be used to rapidly create one ormore empty files. While the touch command does much morethan this, its alternate usage is outside the scope of this class.We'll begin by using the touch command to create severalfiles:$ touch a.txt b.txt c.txt d.txt e.txt f.txtActivity 2: catThe cat command can be used to view the contents of afile. We'll begin by using the echo command to dump datainto a file:$ echo "this is a text file." > g.txtNow let's use the cat command to view the contents of thefile:$ cat g.txtYou should see the phrase "this is a text file." appear on thescreen. We'll discuss alternate usage of the cat commandin future lessons. Now, let's use the ls command to get alist of all files in the current directory (NOTE: that's dash ell,not dash one):$ ls -lActivity 3: mvThe mv command can be used to move files. Until we coverdirectories, you'll likely be using the mv commandprimarily to rename files:$ mv a.txt aa.txt$ mv b.txt bb.txtNow let's use the ls command to see how things havechanged (again, that's dash ell, not dash one):$ ls -lNotice that the files which used to be named a.txt and b.txt havebeen renamed aa.txt and bb.txt respectively. Usethe man command to view the various options forthe mv command:$ man mvActivity 4: cpThe cp command allows you to copy data from one file toanother. Let's copy the file g.txt to gg.txt:$ cp g.txt gg.txtThe ls command will reveal that the copy was successful(again, that's dash ell, not dash one)::$ ls -lNow that we have two copies of the file, let's look at them:$ cat g.txt$ cat gg.txtThe data in these files is identical, so it's impossible to tellthem apart. Let's fix that:$ echo "text file 1" > g.txt$ echo "text file 2" > gg.txtNow let's look at another function of the cat utility."cat" is short for "catenate," meaning "join together." You can usethe cat utility to join several files together:$ cat g.txt gg.txtNotice how the output from this command appears to be the joiningof both files.Activity 5: rmWe can use the rm utility to remove a file (again, that'sdash ell, not dash one)::$ ls -l$ rm c.txt$ ls -lThe output from the second ls command shows how the filec.txt no longer shows up in the file list. Usethe man command to figure out what option causes rm toexplain what is being done. Remove the file d.txt with this optionand verify you see:removed 'd.txt'Activity 6: fileThe file command can be used to show some informationabout various files. Let's look at some files:$ file g.txt$ file f.txt$ file .$ file /bin/lsUse the man page for the file command to figure out howto show the mime data. Run the file command with thatoption on the file g.txt. NOTE: Be aware that this action uses adifferent option on Linux than it does on Unix (e.g., a Mac.)Activity 8: unix2dosThe unix2dos and dos2unix commands can be usedto modify the characters that show up in a file where a \n occurs.The -v option with cat can be used to show non-printablecharacters.$ cat -v g.txtAt the moment, there is no extra data on g.txt. Nowrun unix2dos on g.txt and then run thesame cat command:$ unix2dos g.txt$ cat -v g.txtThe end of the line should now show ^M, signifying a windows/dosnewline instead of the standard \n used in the Linux world.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply