Essential Unix Commands - GeeksforGeeks (2024)

Last Updated : 04 Apr, 2024

Improve

Unix commands are a set of commands that are used to interact with the Unix operating system. Unix is a powerful, multi-user, multi-tasking operating system that was developed in the 1960s by Bell Labs. Unix commands are entered at the command prompt in a terminal window, and they allow users to perform a wide variety of tasks, such as managing files and directories, running processes, managing user accounts, and configuring network settings. Unix is now one of the most commonly used Operating systems used for various purposes such as Personal use, Servers, Smartphones, and many more. It was developed in the 1970’s at AT& T Labs by two famous personalities Dennis M. Ritchie and Ken Thompson.

  • You’ll be surprised to know that the most popular programming language C came into existence to write the Unix Operating System.
  • Linux is Unix-Like operating system.
  • The most important part of the Linux is Linux Kernel which was first released in the early 90s by Linus Torvalds. There are several Linux distros available (most are open-source and free to download and use) such as Ubuntu, Debian, Fedora, Kali, Mint, Gentoo, Arch and much more.
  • Now coming to the Basic and most usable commands of Linux/Unix part. (Please note that all the linux/unix commands are run in the terminal of a linux system.Terminal is like command prompt as that of in Windows OS)
  • Linux/Unix commands are case-sensitive i.e Hello is different from hello.

Basic Unix commands:

Table of Content

  • File System Navigation Unix Command
  • File Manipulation Unix Command
  • Process Management Unix Command
  • Text Processing Unix Command
  • Network Communication Unix Command
  • Text Editors in Unix

File System Navigation Unix Command

Command

Description

Example

cd

Changes the current working directory.

cd Documents

ls

Lists files and directories in the current directory.

ls

pwd

Prints the current working directory.

pwd

mkdir

Creates a new directory.

mkdir new_folder

rmdir

Removes an empty directory.

rmdir empty_folder

mv

Moves files or directories.

mv file1.txt Documents/

File Manipulation Unix Command

Command

Description

Example

touch

Creates an empty file or updates the access and modification times.

touch new_file.txt

cp

Copies files or directories.

cp file1.txt file2.txt

mv

Moves files or directories.

mv file1.txt Documents

rm

Remove files or directories.

rm old_file.txt

chmod

Changes the permissions of a file or directory.

chmod 644 file.txt

chown

Changes the owner and group of a file or directory.

chown user:group file.txt

ln

Creates links between files.

ln -s target_file symlink

catConcatenates files and displays their contents.cat file1.txt file2.txt
headDisplays the first few lines of a file.head file.txt
tailDisplays the last few lines of a file.tail file.txt
moreDisplays the contents of a file page by page.more file.txt
lessDisplays the contents of a file with advanced navigation features.less file.txt
diffCompares files line by line.diff file1.txt file2.txt
patchApplies a diff file to update a target file.patch file.txt < changes.diff

Process Management Unix Command

Command

Description

Example

psDisplays information about active processes, including their status and IDs.ps aux
topDisplays a dynamic real-time view of system processes and their resource usage.top
killTerminates processes using their process IDs (PIDs).kill <pid>
pkillSends signals to processes based on name or other attributes.pkill -9 firefox
killallTerminates processes by name.killall -9 firefox
reniceChanges the priority of running processes.renice -n 10 <pid>
niceRuns a command with modified scheduling priority.nice -n 10 command
pstreeDisplays running processes as a tree.pstree
pgrepSearches for processes by name or other attributes.pgrep firefox
jobsLists active jobs and their status in the current shell session.jobs
bgPuts a job in the background.bg <job_id>
fgBrings a background job to the foreground.fg <job_id>
nohupRuns a command immune to hangups, with output to a specified file.nohup command &
disownRemoves jobs from the shell’s job table, allowing them to run independently.disown <job_id>

Text Processing Unix Command

Command

Description

Example

grepSearches for patterns in text files.grep "error" logfile.txt
sedProcesses and transforms text streams.sed 's/old_string/new_string/g' file.txt
awkProcesses and analyzes text files using a pattern scanning and processing language.awk '{print $1, $3}' data.csv

Network Communication Unix Command

Command DescriptionExample
pingTests connectivity with another host using ICMP echo requests.ping google.com
tracerouteTraces the route that packets take to reach a destination.traceroute google.com
nslookupQueries DNS servers for domain name resolution and IP address information.nslookup google.com
digPerforms DNS queries, providing detailed information about DNS records.dig google.com
hostPerforms DNS lookups, displaying domain name to IP address resolution.host google.com
whoisRetrieves information about domain registration and ownership.whois google.com
sshProvides secure remote access to a system.ssh username@hostname
scpSecurely copies files between hosts over a network.scp file.txt username@hostname:/path/
ftpTransfers files between hosts using the File Transfer Protocol (FTP).ftp hostname
telnetEstablishes interactive text-based communication with a remote host.telnet hostname
netstatDisplays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.netstat -tuln
ifconfigDisplays or configures network interfaces and their settings.ifconfig
iwconfigConfigures wireless network interfaces.iwconfig wlan0
routeDisplays or modifies the IP routing table.route -n
arpDisplays or modifies the Address Resolution Protocol (ARP) cache.arp -a
ssDisplays socket statistics.ss -tuln
hostnameDisplays or sets the system’s hostname.hostname
mtrCombines the functionality of ping and traceroute, providing detailed network diagnostic information.mtr google.com

System Administration Unix Command

Command

Description

Example

df

Displays disk space usage.

df -h

du

Displays disk usage of files and directories.

du -sh /path/to/directory

crontab -e

Manages cron jobs, which are scheduled tasks that run at predefined times or intervals.

crontab -e

Text Editors in Unix

Text EditorDescriptionExample
Vi / VimVi (Vim) is a highly configurable, powerful, and feature-rich text editor based on the original Vi editor. Vim offers modes for both command-line operations and text editing.Open a file with Vim: vim filename
Exit Vim editor: Press Esc, then type :wq and press Enter
EmacsEmacs is a versatile text editor with extensive customization capabilities and support for various programming languages.Open a file with Emacs: emacs filename
Save and exit Emacs: Press Ctrl + X, then Ctrl + S and Ctrl + X, then Ctrl + C to exit
NanoNano is a simple and user-friendly text editor designed for ease of use and accessibility.Open a file with Nano: nano filename
Save and exit Nano: Press Ctrl + O, then Ctrl + X
EdEd is a standard Unix text editor that operates in line-oriented mode, making it suitable for batch processing and automation tasks.Open a file with Ed: ed filename
Exit Ed editor: Type q and press Enter
JedJed is a lightweight yet powerful text editor that provides an intuitive interface and support for various programming languages.Open a file with Jed: jed filename
Save and exit Jed: Press Alt + X, then type exit and press Enter

Unix Commands – FAQs

What is Unix and how does it differ from other operating systems?

This question aims to clarify the unique features and characteristics of Unix compared to other operating systems like Windows or macOS.

Who developed Unix and what is its significance in the history of computing?

Users might want to know about the origins of Unix, its developers, and its role in shaping the modern computing landscape.

What are some popular Unix-like operating systems and how do they relate to Unix?

This question seeks to understand the relationship between Unix and Unix-like systems such as Linux, and the various distributions available for different purposes.

What are the essential Unix commands and how are they used?

Users may seek clarification on the basic Unix commands listed in the article and how they can be applied in practical scenarios.

How can I learn Unix commands and improve my proficiency in using Unix-based systems?

This question targets individuals who are interested in learning more about Unix commands and how to become proficient in utilizing Unix-based operating systems effectively.

Conclusion

In conclusion, Unix commands serve as a fundamental toolkit for navigating and managing the Unix operating system, which has evolved from its inception in the 1960s to become one of the most widely used OS platforms across various domains including personal computing, servers, and mobile devices. From its origins at Bell Labs with developers Dennis M. Ritchie and Ken Thompson to the birth of the C programming language and the subsequent emergence of Unix-like systems such as Linux, the Unix ecosystem has significantly shaped the computing landscape. Understanding basic Unix commands is essential for users to efficiently manipulate files, manage processes, configure networks, and perform system administration tasks, thereby empowering them to leverage the full potential of Unix-based systems for diverse computing needs.



`; tags.map((tag)=>{ let tag_url = `videos/${getTermType(tag['term_id__term_type'])}/${tag['term_id__slug']}/`; tagContent+=``+ tag['term_id__term_name'] +``; }); tagContent+=`
`; return tagContent; } //function to create related videos cards function articlePagevideoCard(poster_src="", title="", description="", video_link, index, tags=[], duration=0){ let card = `

${secondsToHms(duration)}

${title}
${showLessRelatedVideoDes(htmlToText(description))} ... Read More

${getTagsString(tags)}

`; return card; } //function to set related videos content function getvideosContent(limit=3){ videos_content = ""; var total_videos = Math.min(videos.length, limit); for(let i=0;i

'; } else{ let view_all_url = `${GFG_SITE_URL}videos/`; videos_content+=`

View All

`; } // videos_content+= '

'; } } return videos_content; } //function to show main video content with related videos content async function showMainVideoContent(main_video, course_link){ //Load main video $(".video-main").html(`

`); require(["ima"], function() { var player = videojs('article-video', { controls: true, // autoplay: true, // muted: true, controlBar: { pictureInPictureToggle: false }, playbackRates: [0.5, 0.75, 1, 1.25, 1.5, 2], poster: main_video['meta']['largeThumbnail'], sources: [{src: main_video['source'], type: 'application/x-mpegURL'}], tracks: [{src: main_video['subtitle'], kind:'captions', srclang: 'en', label: 'English', default: true}] },function() { player.qualityLevels(); try { player.hlsQualitySelector(); } catch (error) { console.log("HLS not working - ") } } ); const video = document.querySelector("video"); const events =[ { 'name':'play', 'callback':()=>{videoPlayCallback(main_video['slug'])} }, ]; events.forEach(event=>{ video.addEventListener(event.name,event.callback); }); }, function (err) { var player = videojs('article-video'); player.createModal('Something went wrong. Please refresh the page to load the video.'); }); /*let video_date = main_video['time']; video_date = video_date.split("/"); video_date = formatDate(video_date[2], video_date[1], video_date[0]); let share_section_content = `

${video_date}

`;*/ let hasLikeBtn = false; // console.log(share_section_content); var data = {}; if(false){ try { if((loginData && loginData.isLoggedIn == true)){ const resp = await fetch(`${API_SCRIPT_URL}logged-in-video-details/${main_video['slug']}/`,{ credentials: 'include' }) if(resp.status == 200 || resp.status == 201){ data = await resp.json(); share_section_content+= `

`; hasLikeBtn = true; } else { share_section_content+= `

`; } } else { share_section_content+= `

`; } //Load share section // $(".video-share-section").html(share_section_content); // let exitCond = 0; // const delay = (delayInms) => { // return new Promise(resolve => setTimeout(resolve, delayInms)); // } // while(!loginData){ // let delayres = await delay(1000); // exitCond+=1; // console.log(exitCond); // if(exitCond>5){ // break; // } // } // console.log(loginData); /*if(hasLikeBtn && loginData && loginData.isLoggedIn == true){ setLiked(data.liked) setSaved(data.watchlist) }*/ } catch (error) { console.log(error); } } //Load video content like title, description if(false){ $(".video-content-section").html(`

${main_video['title']}

${hideMainVideoDescription(main_video['description'], main_video['id'])}

${getTagsString(main_video['category'])} ${(course_link.length)? `

View Course

`:''} `); let related_vidoes = main_video['recommendations']; if(!!videos && videos.length>0){ //Load related videos $(".related-videos-content").html(getvideosContent()); } } //show video content element = document.getElementById('article-video-tab-content'); element.style.display = 'block'; $('.spinner-loading-overlay:eq(0)').remove(); $('.spinner-loading-overlay:eq(0)').remove(); } await showMainVideoContent(video_data, course_link); // fitRelatedVideosDescription(); } catch (error) { console.log(error); } } getVideoData(); /* $(window).resize(function(){ onWidthChangeEventsListener(); }); $('#video_nav_tab').click('on', function(){ fitRelatedVideosDescription(); });*/ });

Essential Unix Commands - GeeksforGeeks (2024)

References

Top Articles
Latest Posts
Article information

Author: Mr. See Jast

Last Updated:

Views: 6335

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.